NoReverseMatch at /articles/Qiang-Lie-Tui-J/
来源:7-9 django-contrib-comments实现评论文章
归来也无风雨也无晴
2021-08-20
阅读全文是出错,我想应该是article为空。
class ArticleDetailView(LoginRequiredMixin, DetailView):
model = Articles
template_name = 'articles/article_detail.html'
def get_context_data(self, **kwargs):
data = super(ArticleDetailView, self).get_context_data()
print(data)
'''
{'object': <Articles: 强烈推荐让你弯道超车的40个好习惯>,
'articles': <Articles: 强烈推荐让你弯道超车的40个好习惯>,
'view': <zanhu.articles.views.ArticleDetailView object at 0x7fc099f5b5f8>}
'''
return data
<p class="text-left">
<a href="{% url 'users:detail' article.user.username %}">{{ article.user.get_profile_name }}</a>
发表于{{ article.created_at }}
</p>
当article改为articles时,详情页正常了。我看到视频的代码的确是article,不是复数。这里百思不得姐。
app_name = 'articles'
urlpatterns = [
path('', views.ArticlesListView.as_view(), name='list'),
path('write-news-article/', views.ArticlesCreateView.as_view(), name='write-new'),
path('drafts/', views.DraftListView.as_view(), name='drafts'),
path('<str:slug>/', views.ArticleDetailView.as_view(), name='article')
]
但取消评论的注释后,又一个错误。
Internal Server Error: /articles/Qiang-Lie-Tui-Jian-Rang-Ni-Wan-Dao-Chao-Che-De-40Ge-Hao-Xi-Guan/
Traceback (most recent call last):
省略
File "/root/.virtualenvs/zanhu_venv/lib/python3.6/site-packages/django/contrib/contenttypes/models.py", line 27, in _get_opts
model = model._meta.concrete_model
AttributeError: 'str' object has no attribute '_meta'
我代码如下:
THIRD_PARTY_APPS = [
''',
'django_comments',
]
path('comments/', include('django_comments.urls')),
同样也迁移了数据。
{% load static comments crispy_forms_tags thumbnail %}
望大佬指正
写回答
1回答
-
Jack
2021-08-20
您好,这里有for循环所有的artilcles对象
你说“消评论的注释后“是啥意思?哪个地方?
00
相似问题
我出现了这个错不知道是为什么?
回答 1
7.5草稿箱页面报错
回答 2