Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在不同的URL中显示帖子列表_Python_Django - Fatal编程技术网

Python 在不同的URL中显示帖子列表

Python 在不同的URL中显示帖子列表,python,django,Python,Django,Django博客应用程序附带了一个开箱即用的index.html,其中显示了所有帖子的列表 我需要在新的URL中显示此列表,当我从index.html复制html代码并粘贴到planoacao.html时,它不会显示任何内容 这是index.html: {% for post in post_list %} <div class="card mb-4" style="width: 18rem; "> {% if

Django博客应用程序附带了一个开箱即用的index.html,其中显示了所有帖子的列表

我需要在新的URL中显示此列表,当我从index.html复制html代码并粘贴到planoacao.html时,它不会显示任何内容

这是index.html:

 {% for post in post_list %}
                <div class="card mb-4" style="width: 18rem; ">
                    {% if post.get_finalizado_display  == 'Não' %}
                    <!--<p class="card-text text-muted h6"> NOK </p>-->
                    <div class="card-body" style="background-color:#FF0909;">
                    {% else %}
                    <!--<p class="card-text text-muted h6"> ok </p>-->
                    <div class="card-body">
                    {% endif %}
{% endfor %}
这是我的URL.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('blog.urls')),
    url(r'^planoacao/', TemplateView.as_view(template_name="planoacao.html")),
    url(r'calendar', TemplateView.as_view(template_name="calendar.html")),
    url(r'^admin/', admin.site.urls),
    url(r'^', include('blog.urls'), name="Blog"),
    ] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
如何在不同的URL中显示所有帖子的列表?xxx/planoacao.html?简单地从index.html复制html是行不通的


请注意,我不想更改常规index.html帖子列表,我只想添加第二个帖子列表页面。

您似乎想在
/planoacao
上显示您的
PostList
视图,因此在url.py中,您可以将此路径连接到该视图:

url(r'^planoacao/', PostList.as_view()),

请注意,在Django中,视图的路径和使用的模板之间没有直接链接。您可以将任何模板与任何路径一起使用,您所要做的就是定义要在视图中使用的模板。

Django没有现成的index.html。但是,这里的问题是您的“planoacao”URL实际上并不指向您的planoacao视图。@DanielRoseman,因为没有适用于傻瓜的Djangoview,如何修复此问题?我得到一个错误:NameError:“name PosList”不是defined@ROCA您需要在URL.py中导入PostList
url(r'^planoacao/', PostList.as_view()),