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

发布于 2024-11-29 18:14:09 字数 1073 浏览 1 评论 0原文

我做错了什么?

我的网址:http://localhost:8000/login/

来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞美少年 2024-12-06 18:14:09
## urls.py
urlpatterns = patterns('',
  (r'',include('dealerpanel.urls')),
  (r'^admin/', include(admin.site.urls))
)

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

/login/login/
/login/home/
/home/login
...
## urls.py
urlpatterns = patterns('',
  (r'',include('dealerpanel.urls')),
  (r'^admin/', include(admin.site.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:

/login/login/
/login/home/
/home/login
...
孤千羽 2024-12-06 18:14:09

将类似的内容添加到您的dealerpanel/urls.py中,以便http://localhost:8000/login/将访问视图dealerpanel.views.target_view /code>:

urlpatterns = patterns('dealerpanel.views',
  ...
  (r'','target_view'),
)

这意味着login(或home)后的空字符串将与target_view匹配

Add something like this to your dealerpanel/urls.py so that http://localhost:8000/login/ will hit the view dealerpanel.views.target_view:

urlpatterns = patterns('dealerpanel.views',
  ...
  (r'','target_view'),
)

This means the empty string after login (or home) will match the target_view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文