django尝试了这些url模式 [英] django tried these url patterns

查看:224
本文介绍了django尝试了这些url模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试访问我的网站时,它会为我提供以下信息:使用mysite.urls中定义的URLconf,Django按以下顺序尝试了以下URL模式:
^ admin /
当前URL ,,与这些都不匹配。

When I try to access my site, it gives me the following: Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^admin/ The current URL, , didn't match any of these.

如果我转到该站点并附加/ admin,它将带我进入管理页面。如果我注释掉启用管理员的行,它将正常工作。如何获得两者? urlpatterns中的第一个模式是’,因此我不明白为什么在启用管理员后会搞砸。 (注意:我只是在做本教程。)

If I go to the site and append /admin, it takes me to the admin page. If I comment out the line enabling the admin, it works properly. How do I get both? The first pattern in urlpatterns is '', so I don't understand why that messes up when I enable the admin. (Note: I am just doing the tutorial.)

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
#url(r'^$', 'mysite.views.home', name='home'),
# url(r'^x/', include('mysite.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)


推荐答案

常见问题。

当根本没有定义urlpatterns时,Django会给您它起作用了!
祝贺您第一个由Django驱动的页面,但是只要您定义了所有消失的urlpattern即可。

When there are no urlpatterns defined at all, Django gives you the "It worked! Congratulations on your first Django-powered page" message, but as soon as you define any urlpattern that goes away.

出现帽子错误是因为您尚未为根url定义urlpattern,而仅为 / admin定义了urlpattern。继续学习本教程,直到它教您如何添加自己的urlpatters。

You're getting that error because you have not defined a urlpattern for the root url, just one for "/admin". Continue through the tutorial until it teaches you how to add your own urlpatters.

这篇关于django尝试了这些url模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆