7.5草稿箱页面报错
来源:7-5 用户发表文章与保存草稿
荔枝仔
2019-04-29
class ArticlesListView(LoginRequiredMixin, ListView):
"""已发布的文章列表"""
model = Article
paginate_by = 20
context_object_name = "articles"
template_name = "articles/article_list.html" # 可省略
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context['popular_tags'] = Article.objects.get_counted_tags()
return context
def get_queryset(self, **kwargs):
return Article.objects.get_published()
class DraftsListView(ArticlesListView):
"""草稿箱文章列表"""
def get_queryset(self, **kwargs):
# 当前用户的草稿
return Article.objects.filter(user=self.request.user).get_drafts()
http://127.0.0.1:8000/articles/可以访问,
http://127.0.0.1:8000/articles/drafts/报错,
模板article_list.html里面的这段内容是不是没传对参数
{% for article in articles %}
{% endfor %}
望老师指导
2回答
-
这个简单,NoReverseMatch 就是URL解析失败,你看看路由写对了没,这是文章模块开发好的urls.py
from django.urls import path
from zanhu.articles import views
app_name = 'articles'
urlpatterns = [
path('', views.ArticlesListView.as_view(), name='list'),
path('write-new-article/', views.CreateArticleView.as_view(), name='write_new'),
path('drafts/', views.DraftsListView.as_view(), name='drafts'),
path('<str:slug>/', views.DetailArticleView.as_view(), name='article'),
path('edit/<int:pk>/', views.EditArticleView.as_view(), name='edit_article'),
]文章列表和草稿箱页,url不需要传参数
012019-04-29 -
鲨鱼辣椒辣
2020-12-02
好巧 我也是这个问题
122020-12-02
相似问题