2012-09-06 102 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解決了該問題。