python - Django 网址 NoReverseMatch

标签 python django django-urls

我一直在努力解决这个问题,但似乎无法发现我的错误。

在我的 Django 1.6 项目中,我有两个应用程序:holdcontrol

项目urls.py

url(r'^control/$', include('control.urls')),

应用control/urls.py

url(r'^$', views.index, name='control_home'),

#this doesn't work
url(r'^invite/$', views.control_invite, name='control_invite'),

控件views.py

def index(request):
    return render(request, 'control_index.html')


def control_invite(request):
    return render(request, 'control_invite.html')

模板control_index.html

<li class="active"><a href="{% url 'control_home' %}">Control</a></li>
<li><a href="{% url 'control_invite' %}">Invitations</a></li>

错误

Reverse for 'control_invite' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['control/$invite/$']

我在 shell 中遇到了同样的错误。不确定我错过了什么......

最佳答案

您在主 urls.py 的末尾有一个 $ 符号,这意味着该模式应该以 control/ 结束并且不允许任何更多的子 url。将其更改为:

url(r'^control/', include('control.urls')),

关于python - Django 网址 NoReverseMatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20641948/

相关文章:

django - 我的 Django 许多字段都标记为唯一,是否有选项可以删除它?

django - 如何使用 Django 中的通用 View CreateView 自定义表单的 View

python - django url 中的 '_' 有什么作用?

django - 在 Django Rest Framework 中使用 APIView 和 viewset 设置路由器

python - _curses.error : addwstr() returned ERR on changing nlines to 1 on newwin method

python - 如何在Python中基于列表元素创建MySQL表?

python - Django 从外部 api 缓存图像

python - 查找类似功能/产品组合的模式(最好在 python 中)

python - tkinter 应用程序添加右键单击上下文菜单?

Django 表单与 ReactJS