[英]Django Not Recognizing URLs
I am getting a 404 error for a few of my URLs in my django project. 我的django项目中的一些URL收到404错误。 For example:
例如:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Using the URLconf defined in some_project.urls, Django tried these URL patterns, in this order:
^$ [name='home']
^admin/$
But I haven't changed anything to the file. 但我没有改变任何文件。
urls.py urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'views.index',name='home',),
url(r'^admin/$', include(admin.site.urls)),
)
This problem seemed to come after I installed Django Evolve. 在我安装Django Evolve后似乎出现了这个问题。 Not sure if that has something to do with it.
不确定这是否与它有关。
Your request url is http://127.0.0.1:8000/admin
, but your urlpattern is url(r'^admin/$', include(admin.site.urls))
. 您的请求网址是
http://127.0.0.1:8000/admin
,但您的网址是url(r'^admin/$', include(admin.site.urls))
。
There is an extra /
in the urlpattern. urlpattern中有一个额外的
/
。
If you want to include other URLConfs, here's an example to include other URLconfs: 如果你想包含其他URLConfs,这里有一个包含其他URLconf的例子:
from django.conf.urls import include, patterns, url
urlpatterns = patterns('',
# ... snip ...
url(r'^comments/', include('django.contrib.comments.urls')),
url(r'^community/', include('django_website.aggregator.urls')),
url(r'^contact/', include('django_website.contact.urls')),
# ... snip ...
)
As Burhan correctly pointed out, you need to remove the trailing $
so that include
could work. 正如Burhan正确指出的那样,你需要删除尾随
$
以便include
可以工作。
The reason is because in regex trailing $ matches right after the last character in the string
. 原因是因为正则表达式
trailing $ matches right after the last character in the string
。
你的模式不正确,它应该是:
url(r'^admin/', include(admin.site.urls)),
It was a problem with the settings file. 这是设置文件的问题。 There was a merge problem with what I had and another developer had.
我和其他开发人员有合并问题。
The /$ wasn't related to this problem. / $与此问题无关。 I added it when I was trouble shooting.
当我遇到麻烦时我加了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.