Python 3.8.3 Django 3.1.3
Eu não estou entendendo o motivo desse erro estar acontecendo.
Reverse for 'post_detail' not found. 'post_detail' is not a valid view function or pattern name.
A linha que o erro acusa é:
<li><a href="{% url 'post_detail' post.id %}" class="button">Read More</a></li>
A função está criada no 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})
O URLs importa o módulo do post_detail, e usa ele pra criar um link novo de acordo com o id a cada 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 }}
O Código funciona perfeitamente bem, até eu inserir a linha de comando pra redirecionar o 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>
Assim que eu insiro o a linha:Read More