0
Python 3.8.3 Django 3.1.3
I don’t understand why this mistake is happening.
Reverse for 'post_detail' not found. 'post_detail' is not a Valid view Function or Pattern name.
The line the error accuses is:
<li><a href="{% url 'post_detail' post.id %}" class="button">Read More</a></li>
The function is created in views.py:
blog/blog/views.py
from django.shortcuts import render
from website.models import Post
def post_detail(request, id):
post = Post.objects.get(id=id)
return render(request, 'post_detail.html', {'post': post})
Urls imports the post_detail module, and uses it to create a new link according to the id of each post.
website/urls.py
from django.urls import path, include
from .views import hello_blog, post_detail
urlpatterns = [
path('', hello_blog),
path('post/<int:id>/', post_detail, name='post_detail'),
]
blog/website/templates/post_detail.html
<h1>Meu Post</h1>
{{ post }}
The Code works perfectly well, until I enter the command line to redirect the link: blog/website/templates/index.html
<html>
<section id="two">
<h2>Recent Work</h2>
<div class="row">
{% for post in posts %}
<article class="col-6 col-12-xsmall work-item">
<a href="{% static 'images/fulls/01.jpg' %}" class="image fit thumb"><img src="{% static 'images/thumbs/01.jpg' %}" alt="" /></a>
<h3>{{ post.title }}</h3>
<p>{{ post.sub_title }}</p>
<span> {{ post.get_category_label }} </span>
<ul class="actions">
<li><a href="{% url 'post_detail' post.id %}" class="button">Read More</a></li>
</ul>
</article>
{% endfor %}
</div>
</html>
As soon as I insert the line:Read More