以下是我来自views.py的代码
from . import views
app_name = 'blogs'
urlpatterns = [
path('', views.blogs_home, name='blogs'),
path('<int:post_id>', views.single_blog, name='detailed_view'),
]
以下代码来自views.py
def single_blog(request,post_id):
blog_single = Blogs.objects.get(id=post_id)
context = {'blog_single': blog_single}
template = 'blog_home.html'
return render(request, template, context)
和html如下
{% for b in blogs %}
<div>
<h1><a href="{% url 'blogs:detailed_view' id=b.id %}">{{ b.title }}</a></h1>
<p>{{ b.body }}</p>
<aside>{{ b.date }}</aside>
</div>
{% endfor %}
但是,它返回'detailed_view'的错误反向,但没有找到参数。
能请您解释和纠正。谢谢
杰夫
答案 0 :(得分:0)
Change the line in html to :
<h1><a href="{% url 'blogs:detailed_view' post_id=b.id %}">{{ b.title }}</a></h1>