错误跟踪:
NoReverseMatch at /search/
Reverse for '/about/murder-in-the-curtain' not found. '/about/murder-in-the-curtain' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://127.0.0.1:8000/search/?q=mur
Django Version: 1.11.6
Exception Type: NoReverseMatch
Exception Value:
Reverse for '/about/murder-in-the-curtain' not found. '/about/murder-in-the-curtain' is not a valid view function or pattern name.
URL配置:
url(r'^about/(?P<slug>[-\w]+)$', about_pages, name="about_pages")
型号:
class Book(models.Model):
slug = models.SlugField(default = "")
def get_absolute_url(self):
reverse("about_pages", kwargs = {"slug" : self.slug})
模板:
{% for result in results %}
<a href = {% url result.get_absolute_url %}>{{result.name}}</a>
{% endfor %}
我的正则表达式还好吗? 我觉得它正确地生成了url,但是没有在URLConf中找到匹配的模式来导航到一个视图。你知道吗
get_absolute_url
方法反转url并返回它,因此您不必对其使用{% url %}
标记。将模板更改为:你不应该这样使用它,因为它是一个Book方法,而不是url路径
所以你应该写在这里
相关问题 更多 >
编程相关推荐