0

我是 Django 新手,我正在关注激活管理站点的教程。我从教程中做了以下配置:

  • 首先,我取消了django.contrib.adminsettings.py 的应用程序部分中的行的注释。

  • python manage.py syncdb然后我在终端中执行了命令。

  • 然后我取消了urls.py 中的from django.contrib import admin,admin.autodiscover()​​ 和行的注释;url(r'^admin/', include(admin.site.urls))结果代码是:

    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'^mysite/', 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)),
    )
    

当我运行项目时,出现以下错误:

Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/

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.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

我能做些什么?


感谢您的回答,但是当我尝试访问时,http://127.0.0.1:8000/admin出现以下错误:

DoesNotExist at /admin/

Site matching query does not exist. Lookup parameters were {'pk': 1}

Request Method:     GET
Request URL:    http://127.0.0.1:8000/admin/
Django Version:     1.5
Exception Type:     DoesNotExist
Exception Value:    

Site matching query does not exist. Lookup parameters were {'pk': 1}

Exception Location:     /usr/local/lib/python2.7/dist-packages/django/db/models/query.py in get, line 401
Python Executable:  /usr/bin/python
Python Version:     2.7.3
Python Path:    

['/home/eren/mysite',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

Server time:    Fri, 24 May 2013 23:29:03 +0300
4

1 回答 1

2

http://127.0.0.1:8000/admin您应该在not访问管理站点http://127.0.0.1:8000/

注:admin后缀。

于 2013-05-24T04:43:05.973 回答