gpt4 book ai didi

python - 无法匹配 Django 中 URL.conf 中的 URL?

转载 作者:太空宇宙 更新时间:2023-11-04 10:59:04 24 4
gpt4 key购买 nike

我做错了什么?

My URL : http://localhost:8000/login/

来自 Django 的 DEBUG 日志:

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))
)

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')
)

最佳答案

## urls.py
urlpatterns = patterns('',
(r'',include('dealerpanel.urls')),
(r'^admin/', include(admin.site.urls))
)

将包含 dealerpanel.urls 的前缀更改为空字符串。我认为您构建它的方式实际上是在寻找像这样的网址:

/login/login/
/login/home/
/home/login
...

关于python - 无法匹配 Django 中 URL.conf 中的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7055617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com