0

我遵循Django教程第1部分,現在在第2部分,我應該讓管理界面啓動並運行。在教程中的URL匹配失敗(管理員)

我非常認真地跟着一步,但是當我嘗試加載網站,我收到以下錯誤:

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: 
1. ^admin/ 
The current URL, , didn't match any of these. 

settings.py第一註釋掉「django.contrib.admin」:

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', 
    'polls', 
) 

... ...之後,我跑蟒蛇manage.py執行syncdb,其輸出:

Creating tables ... 
Installing custom SQL ... 
Installing indexes ... 
Installed 0 object(s) from 0 fixture(s) 

...然後我未註釋的是我應該根據教程,在urls.py的三行:

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)), 
) 

如上所述,這如果運行產生錯誤消息。

什麼可能是錯的?我的意思是我完全按照假設跟着教程。

+0

你有沒有嘗試添加admin.py投票? https://docs.djangoproject.com/zh/dev/intro/tutorial02/#make-the-poll-app-modifiable-in-the-admin – Pramod 2013-02-24 16:19:11

+0

現在嘗試了。一樣。 – holyredbeard 2013-02-24 16:24:08

回答

2

注意本教程中的指令:

Now, open a Web browser and go to 「/admin/」 on your local domain – e.g., http://127.0.0.1:8000/admin/ .

添加錯誤顯示,您試圖去根網址,而不是/admin/遵醫囑。

+0

哈哈。有時解決方案太容易看到。謝謝 ;) – holyredbeard 2013-02-24 16:31:43