无法匹配 Django 中 URL.conf 中的 URL?
我做错了什么?
来自 Django 的调试日志:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/login/
Using the URLconf defined in dealers.urls, Django tried these URL patterns, in this order:
^login|home/ ^login/$
^login|home/ ^home/$
^login|home/ ^home/dealer/(?P<dealer_id>\d+)/$
^admin/
The current URL, login/, didn't match any of these.
urls.py 文件:
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^login|home/',include('dealerpanel.urls')),
(r'^admin/', include(admin.site.urls))
)
经销商面板/urls.py :
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('dealerpanel.views',
(r'^login/$','login'),
(r'^home/$','home'),
(r'^home/dealer/(?P<dealer_id>\d+)/$','details')
)
What am I doing wrong ?
My URL : http://localhost:8000/login/
The DEBUG log from Django :
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/login/
Using the URLconf defined in dealers.urls, Django tried these URL patterns, in this order:
^login|home/ ^login/$
^login|home/ ^home/$
^login|home/ ^home/dealer/(?P<dealer_id>\d+)/$
^admin/
The current URL, login/, didn't match any of these.
urls.py file :
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^login|home/',include('dealerpanel.urls')),
(r'^admin/', include(admin.site.urls))
)
dealerpanel/urls.py :
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('dealerpanel.views',
(r'^login/
,'login'),
(r'^home/
,'home'),
(r'^home/dealer/(?P<dealer_id>\d+)/
,'details')
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将包含
dealerpanel.urls
的前缀更改为空字符串。我认为你的结构方式实际上是在寻找像这样的网址:Change the prefix for including
dealerpanel.urls
to be the empty string. I think the way you have it structured it would actually be looking for a url like:将类似的内容添加到您的dealerpanel/urls.py中,以便http://localhost:8000/login/将访问视图dealerpanel.views.target_view /code>:
这意味着
login
(或home
)后的空字符串将与target_view
匹配Add something like this to your
dealerpanel/urls.py
so thathttp://localhost:8000/login/
will hit the viewdealerpanel.views.target_view
:This means the empty string after
login
(orhome
) will match thetarget_view