社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Walucas

Walucas 最近创建的主题
Walucas 最近回复了
6 年前
回复了 Walucas 创建的主题 » 包含在django模板中的筛选器

您应该创建一个filter标记,它将接收您的queryset并返回一个filtered标记。。。。您可以在此处找到详细信息:

https://docs.djangoproject.com/en/2.1/howto/custom-template-tags/

6 年前
回复了 Walucas 创建的主题 » Django表单-如何创建“保存并新建”按钮?

您可以检查您的视图中按下了哪个输入,并根据它,重定向到列表或新的空白表单。

6 年前
回复了 Walucas 创建的主题 » 使用特定状态代码在django中重定向

使用 HttpResponse

from django.http import HttpResponse
def yourView(request):    
    return HttpResponse('401 Unauthorized', status=401)

在这里找到了解决方案: How do I return a 401 Unauthorized in Django?

6 年前
回复了 Walucas 创建的主题 » 在另一个Django应用程序中使用数据

你快到了。试试这个:

views.py

from news.models import News
from django.shortcuts import render

def HomePageView(request):
    context = {}
    news = News.objects.order_by('-date')[:3]  
    context['news']=news 
    return render(request,'home.html',context)

home.html

    {% extends 'base.html' %}

    {% block title %}Home{% endblock title %}

    {% block content %}
        <div class="jumbotron">
            <h1 class="display-4">Lakeland Cycle Club</h1>
            <p class="lead">The home of cycling in Fermanagh.</p>
            <p class="lead">
                <a class="btn btn-primary btn-lg" href="{% url 'news_list' %}" role="button">View All Club News</a>
            </p>
             <span class="font-weight-bold">
               {%for new in news%}
{{new.title}}
{%endfor%}
            </span>
        </div>
    {% endblock content %}