python - 未找到没有参数的“detailed_view”反向
问题描述
以下是来自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”的错误反向,没有找不到参数。
能否请您解释并纠正。谢谢
杰夫
解决方案
将 html 中的行更改为:
<h1><a href="{% url 'blogs:detailed_view' post_id=b.id %}">{{ b.title }}</a></h1>
推荐阅读
- python - rolling.apply 用于需要多列数据框以减少单列的自定义函数
- javascript - CSS对齐和边距问题
- android - onNew 意图返回旧数据
- css - 在项目之间绘制边框,无论它们是并排放置还是换行
- regex - 嵌套 IF 公式未正确评估
- django-rest-framework - 如何在序列化器字段中的查询集上应用 LIMIT?
- javascript - parseFloat() 函数解析一个参数并返回一个浮点数,但在使用它后与我一起 Retrieve Nan
- c# - 倾斜图像后 GDI C# 删除背景
- ios - 消息显示在错误的一侧并且大小/内容不正确(MessageKit)
- reactjs - 向类组件添加 const 以在 Gatsby 站点中显示来自 Contentful CMS 的数据