Django NoReverseMatch 错误:未找到参数 '('',)' 的 'course_detail' 反向

问题描述 投票:0回答:1

我遇到了 Django 的 URL 反转问题。每当我尝试访问由 {% url 'course_detail' course.id %} 模板标记生成的 URL 时,我都会收到以下错误:

enter image description here

这是我的代码的相关部分:

html

enter image description here

这是我在 urls.py 文件中定义 URL 模式的方法:

url.py

enter image description here

我将 course.id 作为 URL 查找的参数传递,但它似乎没有被正确识别。谁能帮助我理解为什么会发生此错误以及如何解决它?

django django-rest-framework django-templates
1个回答
0
投票

请不要使用图像作为代码示例。

在生成期间的上下文中,您没有变量

course_id

可能你的意思是

course.id
。在这种情况下,模板中的 url 定义应该是:

 {% url 'course_detail' course.id %} 

在上下文中你应该有一个

course
实例

© www.soinside.com 2019 - 2024. All rights reserved.