Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django中具有命名空间的NoReverseMatch_Python_Django_Django Urls - Fatal编程技术网

Python Django中具有命名空间的NoReverseMatch

Python Django中具有命名空间的NoReverseMatch,python,django,django-urls,Python,Django,Django Urls,在Django中,我不能在不抛出NoReverseMatch的情况下进行反转,即使没有反转,页面也会加载。 以下是相关代码: main/url.py from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'(^$)|(^admin/)',include('example_admin.urls',namespace='example_admin')), ) from djan

在Django中,我不能在不抛出NoReverseMatch的情况下进行反转,即使没有反转,页面也会加载。 以下是相关代码:

main/url.py

from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
    url(r'(^$)|(^admin/)',include('example_admin.urls',namespace='example_admin')),
)
from django.conf.urls import patterns, include, url
from example_admin import views
urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
)
示例_admin/url.py

from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
    url(r'(^$)|(^admin/)',include('example_admin.urls',namespace='example_admin')),
)
from django.conf.urls import patterns, include, url
from example_admin import views
urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
)
示例_admin/views.py

from django.shortcuts import render
def index(request):
    context = {}
    return render(request, 'example_admin/index.hmtl', context)
在我把这一行放进index.html模板之前,一切都很顺利

<a href="{% url 'example_admin:index' %}">LNK</a>

我得到这个错误: 未找到参数为“()”且关键字参数为“{}”的“索引”的反向。已尝试1个模式:[u'(^$)|(^admin/)$']


我也在django shell中尝试过使用reverse('index')和reverse('example_admin:index'),但这两种方法都不适用于我。

我通过将main/url.py中的链接从

url(r'(^$)|(^admin/)',include('example_admin.urls',namespace='example_admin')),

我猜它真的不喜欢我的正则表达式或语句,有人知道为什么吗?

从shell中我运行了resolve('/admin/'),得到了ResolverMatch(func=,args=(),kwargs={},url\u name='index',app\u name='None',namespace='example\u admin'),就是因为这样。