2012-09-06 72 views
2

我不明白为什么Django不加载管理页面。它似乎甚至没有阅读我正在编辑的urls.py文件 - 因为即使我注释掉了'urlpattern'语句,它仍然会在我运行服务器时加载本地hello页面。Django 1.4.1不加载管理网站(Django图书教程)

这是错误消息:

Page not found (404) 
Request Method: GET 
Request URL: http://127.0.0.1:8000/admin 
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: 
^hello/$ 
^time/$ 
^time/plus/(\d{1,2})/$ 
The current URL, admin, didn't match any of these. 

这是我的URL模式代码:

from django.conf.urls import patterns, include, url 
from mysite.views import * 

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

urlpatterns = patterns('', 
    ('^hello/$', hello,), 
    ('^time/$', current_datetime,), 
    (r'^time/plus/(\d{1,2})/$', hours_ahead,), 
    # 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)) 
) 

这是一个片段OS我的settings.py文件:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    # 'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    # 'django.contrib.messages.middleware.MessageMiddleware' 
    # Uncomment the next line for simple clickjacking protection: 
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware', 
) 

ROOT_URLCONF = 'mysite.urls' 

# Python dotted path to the WSGI application used by Django's runserver. 
WSGI_APPLICATION = 'mysite.wsgi.application' 

TEMPLATE_DIRS = (
    '/Users/pavelfage/Desktop/Coding/mysite/Templates', 
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 
    # Always use forward slashes, even on Windows. 
    # Don't forget to use absolute paths, not relative paths. 
) 

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    # 'django.contrib.messages', 
    # 'django.contrib.staticfiles', 
    # Uncomment the next line to enable the admin: 
    'django.contrib.admin', 
    # Uncomment the next line to enable admin documentation: 
    # 'django.contrib.admindocs', 
    'mysite.books' 
) 

任何非常感谢!

+0

您请求的网址是“http://127.0.0.1:8000/admin”,您是否尝试过使用斜杠“http://127.0.0.1:8000/admin/”? – monkut

+0

嗨monkut - 刚试过,结果相同(没有结果)。我认为Django甚至没有查看我正在编辑的urls.py和/或settings.py文件 - 是否有办法找出它正在查找的位置,或者指示它查看特定的文件,这可以通过pythonpath完成? – entrepaul

+0

这不会起作用,否则/ admin会在错误消息中显示 – karthikr

回答

1

我有同样的问题。你可以试试这个:

  • 在你的urls.py这个调用替换包括(admin.site.urls):admin.site.urls

  • 在你setting.py如果不有任何TEMPLATE_CONTEXT_PROCESSORS财产(这是我的情况)补充一点:

    TEMPLATE_CONTEXT_PROCESSORS =( “django.contrib.auth.context_processors.auth”, “django.core.context_processors.debug”,“django.core.context_processors.i18n “,”django.core.context_processors.media“,”django.core.context_processors.static“,”django.core.context_processors.tz“,”django.contrib.messages.context_proces sors.messages“)

它接缝为大致在一个普通的Django 1.4配置的默认属性。在settings.py你的INSTALLED_APPS财产

# 'django.contrib.messages', 
# 'django.contrib.staticfiles', 

,但我不知道这件事:这里是文档说起吧:djangoproject-doc1djangoproject-doc2

您可能还需要取消注释字符串。

对不起没有更好地解释这些变化的原因,但我是一个django初学者。我刚刚发现你的问题对应我的问题,然后是一个可能的awnser。

我希望它可以帮助你。

编辑:在评论见过你可能会尝试删除关于管理界面

2

我面临同样的问题的URL行的URL(...)指令。在urls.py中取消from django.contrib import admin解决了该问题。