【发布时间】:2021-04-30 07:47:36
【问题描述】:
在渲染我的 django 项目的页面时,我收到以下错误,即使 HTML 代码的关键部分已被注释掉:
NoReverseMatch at /current/
'blog' is not a registered namespace
Request Method: GET
Request URL: http://localhost:8000/current/
Django Version: 3.1.5
Exception Type: NoReverseMatch
Exception Value:
'blog' is not a registered namespace
Exception Location: /home/user/.virtualenvs/Django3_course/lib/python3.9/site-packages/django/urls/base.py, line 83, in reverse
Python Executable: /home/user/.virtualenvs/Django3_course/bin/python
Python Version: 3.9.0
Python Path:
['/home/user/.../todowoo_project',
'/home/user/.../todowoo_project',
'/home/user/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts',
'/home/user/.pyenv/versions/3.9.0/lib/python39.zip',
'/home/user/.pyenv/versions/3.9.0/lib/python3.9',
'/home/user/.pyenv/versions/3.9.0/lib/python3.9/lib-dynload',
'/home/user/.virtualenvs/Django3_course/lib/python3.9/site-packages']
Server time: Tue, 26 Jan 2021 13:56:35 +0000
Error during template rendering
In template /home/.../todo/templates/todo/base.html, error at line 97
'blog' is not a registered namespace
[...]
有问题的注释掉的代码如下:
<!-- <li>
<a role="button" href="{% url 'blog:all_blogs' %}" class="btn btn-primary">Blog</a>
</li> -->
我想保留这个以防我需要提醒自己如何将 URL 发送到我的 django 项目中的另一个应用程序,在本例中称为 'blog'。为什么不能注释掉,留在原地,让渲染过程忽略?
即使wrapping it as php-code 也不起作用:
<?php
<!-- <li>
<a role="button" href="{% url 'blog:all_blogs' %}" class="btn btn-primary">Blog</a>
</li> -->
?>
【问题讨论】:
标签: html django django-templates comments html-rendering