2014-08-29 66 views
0

我目前正在使用一個系統,在/{username}中輸入網址時,任何人都可以看到用戶的公開個人資料。如何讓我的django管理控制檯URL優先?

這有點優先,所以我不能再訪問管理控制檯/admin

我該如何讓/admin優先?

urls.py

from django.conf.urls import patterns, include, url 
from django.contrib import admin 

admin.autodiscover() 

urlpatterns = patterns('', 
(r'^player/', include('player_details.urls')), 
(r'^profile/', include('userprofile.urls')), 
url(r'^admin/', include(admin.site.urls)), # enable administration 
url(r'^(?P<username_in_url>\w+)/$', 'fantasymatchday_1.views.public_profile'), #user public profile logged in 
url(r'^(?P<username_in_url>\w+)/$', 'fantasymatchday_1.views.public_profile_anon'), #user public profile anonymous 
) 

URL的將玩家和配置文件的應用程序正常工作,我究竟做錯了什麼?

回答

1

您對該問題的診斷錯誤。您在對Simeon的評論中引用的錯誤並不表示管理員網址將進入個人資料頁面:反正它不會,因爲管理模式已經位於您的網址的個人資料之前。

但是,錯誤很明顯:視圖函數「fantasymatchday_1.views.public_profile_anon」不存在。創建它,或者從網址中刪除對它的引用。 (它看起來完全不相關,因爲它與之前的URL完全相同,因此它永遠不會被調用。但是,如果從urlpatterns引用它,它仍然需要存在)。

+0

啊我看到,沒有意識到它必須存在的其他人以上才能正常工作。謝謝! – Matchday 2014-08-29 14:25:44

0

你需要首先把管理網址:

urlpatterns = patterns('', 
    url(r'^admin/', include(admin.site.urls)), # enable administration 
    ... 

這意味着它會匹配針對URL第一,對「管理」一詞,它會接着顯示管理面板。對於其他網址,它會繼續,並且會根據這些網址匹配玩家名稱。

+0

我試過了仍然不起作用。錯誤消息是'ViewDoesNotExist at/admin/ 無法導入fantasymatchday_1.views.public_profile_anon。視圖在模塊fantasymatchday_1.views中不存在。' – Matchday 2014-08-29 13:55:19

+0

此外,它已經超出了用戶名行,所以肯定它應該與該理論無論如何工作 – Matchday 2014-08-29 13:56:14