django urlpatterns命令 [英] django urlpatterns order
问题描述
否FlatPage与给定的文件相匹配,加载了我的django网站的管理员部分遇到问题查询。
我设法解决了这个问题,但我试图理解为什么它解决了这个问题。在我的urls.py文件中,我将url(r'',include('django.contrib.flatpages.urls')),之后的url(r'^ admin /',include admin.site.urls)),瞧,它的工作。有人可以简单地解释一下为什么会产生相关的区别?管理员网址应该始终位于列表的顶部吗?
代码产生错误:
urlpatterns = patterns(' ',
#示例:
#url(r'^ $','mysite.views.home',name ='home'),
#url(r'^ mysite /' ,include('mysite.foo.urls')),
url(r'^ blog /',include('blog.urls')),
#取消注释下面的admin / doc行启用管理员文档:
#url(r'^ admin / doc /',include('django.contrib.admindocs.urls')),
url(r' ,include('django.contrib.flatpages.urls'))
#取消注释下一行以启用admin:
url(r'^ admin /',include(admin.site.urls) ),
)
这是django 1.4。
问题是您尚未安装 flatpages application 正确。 Django的平板应用程序依赖于一段中间件拦截了404个请求。因此,您不需要将 django.contrib.flatpages.urls
添加到您的 urls.py
中。
您收到该错误,因为您正在使用的正则表达式(''
)匹配全部网址。因此,urlpattern从未达到 ^ admin /'
。
I ran into a problem loading the admin section of my django site with the following error:
No FlatPage matches the given query.
I managed to solve the problem, but I'm attempting to understand why it solved the problem. In my urls.py file, I moved the url(r'', include('django.contrib.flatpages.urls')), after the url(r'^admin/', include(admin.site.urls)), and voila, it worked. Can someone explain, briefly, why this would make a relevant difference? Should the admin url always be at the top of the list?
Code the produced the error:
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
url (r'^blog/', include('blog.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'', include('django.contrib.flatpages.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
This is django 1.4.
The problem is that you have not installed the flatpages application correctly. Django's flatpages application relies on a piece of middleware that intercepts 404 requests. As a result, you do not need to add django.contrib.flatpages.urls
to your urls.py
.
You received that error because the regex you are using (''
) matches all URLs. As a result, the urlpattern never reached ^admin/'
.
这篇关于django urlpatterns命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!