I have the following code in the urls.py in mysite project.
url中有如下代码。py mysite项目。
/mysite/urls.py
/ mysite / urls . py
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^gallery/$', include('mysite.gallery.urls')),
)
This results in a 404 page when I try to access a url set in gallery/urls.py.
当我试图访问gallery/urls.py中设置的url时,这会导致一个404页面。
/mysite/gallery/urls.py
/ mysite /画廊/ urls . py
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^gallery/browse/$', 'mysite.gallery.views.browse'),
(r'^gallery/photo/$', 'mysite.gallery.views.photo'),
)
404 error
404错误
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^gallery/$
The current URL, gallery/browse/, didn't match any of these.
Also, the site is hosted on a media temple (dv) server and using mod_wsgi
此外,该站点驻留在媒体圣殿(dv)服务器上,并使用mod_wsgi
1 个解决方案
#1
17
Remove the $
from the regex of main urls.py
从主url .py的regex中删除$
urlpatterns = patterns('',
(r'^gallery/', include('mysite.gallery.urls')),
)
You don't need gallery
in the included Urlconf.
你不需要包括Urlconf在内的图库。
urlpatterns = patterns('',
(r'^browse/$', 'mysite.gallery.views.browse'),
(r'^photo/$', 'mysite.gallery.views.photo'),
)
Read the django docs for more information
阅读django文档了解更多信息
Note that the regular expressions in this example don't have a
$
(end-of-string match character) but do include a trailing slash. Whenever Django encountersinclude()
, it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing.注意,本例中的正则表达式没有$(字符串结束匹配字符),但是包含一个尾斜杠。每当Django遇到include()时,它会删除与该点匹配的URL的任何部分,并将剩余的字符串发送给所包含的URLconf以进行进一步处理。
#1
17
Remove the $
from the regex of main urls.py
从主url .py的regex中删除$
urlpatterns = patterns('',
(r'^gallery/', include('mysite.gallery.urls')),
)
You don't need gallery
in the included Urlconf.
你不需要包括Urlconf在内的图库。
urlpatterns = patterns('',
(r'^browse/$', 'mysite.gallery.views.browse'),
(r'^photo/$', 'mysite.gallery.views.photo'),
)
Read the django docs for more information
阅读django文档了解更多信息
Note that the regular expressions in this example don't have a
$
(end-of-string match character) but do include a trailing slash. Whenever Django encountersinclude()
, it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing.注意,本例中的正则表达式没有$(字符串结束匹配字符),但是包含一个尾斜杠。每当Django遇到include()时,它会删除与该点匹配的URL的任何部分,并将剩余的字符串发送给所包含的URLconf以进行进一步处理。