我不明白爲什麼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'
)
任何非常感謝!
您請求的網址是「http://127.0.0.1:8000/admin」,您是否嘗試過使用斜槓「http://127.0.0.1:8000/admin/」? – monkut
嗨monkut - 剛試過,結果相同(沒有結果)。我認爲Django甚至沒有查看我正在編輯的urls.py和/或settings.py文件 - 是否有辦法找出它正在查找的位置,或者指示它查看特定的文件,這可以通過pythonpath完成? – entrepaul
這不會起作用,否則/ admin會在錯誤消息中顯示 – karthikr