I could not find the cause of the error.
Urls.py:
path('', views.post_list, name="post_list"),
path('<str:url_sistem>/', views.post_detail, name='post-detail'),
Views.py:
def post_detail(request, url_sistem):
url_sistem = Post.objects.get(title)
posts = get_object_or_404(Post, url_sistem=url_sistem)
return render(request, 'blog/post_detail.html', {'posts':posts})
A href link:
<a href="{% url 'post-detail' post.url_sistem %}" style="color:black;">
You have an indentation error that needs to be fixed:
def post_detail(request, url_sistem):
url_sistem = Post.objects.get(title)
posts = get_object_or_404(Post, url_sistem=url_sistem)
return render(request, 'blog/post_detail.html', {'posts':posts})
in the template:
<a href="{% url 'blog:post-detail' post.url_sistem %}" style="color:black;">
它应该像<a href="{% url 'projectAppName:post-detail' post.url_sistem %}" style="color:black;">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.