urls.py
path('posts/',views.posts,name='posts'),
path('<id>',views.detail_view,name='detail_view'),
views.py
def posts(request):
posts = Post.objects.all().order_by('-date_added')
context = {'posts':posts}
return render(request, 'mains/post.html', context)
post.html
{% block content %}
{% for topic in posts %}
<a>{{ topic.description}}</a> <a href="{% url 'mains:detail_view'
topic.post_owner.id %}">Show
More</a><br>
<br>
{% empty %}
No yet.</li>
{% endfor %}
帖子匹配查询不存在。当我在帖子页面中单击show_more时,会出现此错误。请帮助我。非常感谢您的帮助。
你应该用这个
<a href="{% url 'mains:detail_view' topic.id %}">
代替
<a href="{% url 'mains:detail_view' topic.post_owner.id %}">
因为您要在views.py中传递pk,而不是在模板中传递
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句