【问题标题】:Reverse for 'detailed_view' with no arguments not found未找到没有参数的“detailed_view”反向
【发布时间】:2019-04-14 00:57:18
【问题描述】:

以下是来自 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”的错误反向,但未找到任何参数。

请您解释并纠正。谢谢你

杰夫

【问题讨论】:

  • 请显示确切的错误和完整的回溯。
  • 也显示blogs_home 查看

标签: python django django-templates django-views django-urls


【解决方案1】:

将html中的行改为:

<h1><a href="{% url 'blogs:detailed_view' post_id=b.id %}">{{ b.title }}</a></h1>

【讨论】:

    猜你喜欢
    • 2019-08-03
    • 1970-01-01
    • 2021-11-09
    • 2019-09-14
    • 2020-03-05
    • 2021-03-01
    • 2021-03-13
    • 2018-12-28
    • 2010-12-22
    相关资源
    最近更新 更多