0

我正在使用python默认开发http服务器,它工作正常。错误,当前 URL,,不匹配任何这些,在“http://127.0.0.1:8000 我的软件版本:django 1.4 python 2.6.6

我的 urls.py 文件:

from django.conf.urls import patterns, include, url
#from django.conf.urls.defaults import *

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

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'djproject.views.home', name='home'),
    # url(r'^djproject/', include('djproject.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/', admin.site.urls),
    url(r'^admin/', admin.site.urls),
)

错误:

Page not found (404)
    Request Method:     GET
    Request URL:    http://127.0.0.1:8000/
Using the URLconf defined in djproject.urls, Django tried these URL patterns, in this order:

    ^admin/

The current URL, , didn't match any of these.
4

2 回答 2

2

目前在您的项目中安装的唯一 url 是那些前缀为admin/.

您尝试获取的那个不是以这个前缀开头的。

尝试:http://127.0.0.1:8000/admin/

看起来您刚刚开始使用 django:您完成本教程了吗?

于 2012-06-20T05:39:11.460 回答
1

如果您查看其中注释掉的“示例”部分,urlpatterns您将看到这一行:

# url(r'^$', 'djproject.views.home', name='home'),

这是默认的模式和视图。取消注释,并设置您需要的视图和参数。并阅读教程

于 2012-06-20T05:50:28.810 回答