问题描述
我当前正在使用一个系统,在该系统中,当输入 / {username}
作为URL时,任何人都可以看到用户的公开个人资料。
I am currently using a system where anybody can see a user's public profile when typing in /{username}
as a URL.
这已经获得了优先考虑,因此我无法再访问管理控制台 / admin
。
This has somehow taken priority so therefore I cannot anymore access the admin console /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正常工作,我在做什么错了?
The URL's going to the player and profile apps work fine, what am I doing wrong?
推荐答案
您对问题的诊断是错误的。您在Simeon的注释中引用的错误并不表示管理URL即将进入配置文件页面:无论如何,它不会,因为管理模式已经在您的URL中位于配置文件之前。
Your diagnosis of the problem is wrong. The error you quote in the comment to Simeon does not indicate that the admin URL is going to the profile page: it wouldn't, anyway, because the admin pattern already comes before the profile one in your urls.
但是,错误非常明显:视图函数 fantasymatchday_1.views.public_profile_anon不存在。创建它,或者从URL中删除对其的引用。 (无论如何,它似乎完全无关紧要,因为它的URL与之前的URL完全相同,因此它将永远不会被调用。不过,如果您从urlpatterns引用它,它仍然必须存在。)
The error is, however, quite clear: the view function "fantasymatchday_1.views.public_profile_anon" does not exist. Either create it, or remove the reference to it from the urls. (It seems completely irrelevant anyway, as it has exactly the same url as the one before it, so it will never be invoked. It needs to exist anyway if you reference it from urlpatterns, though.)
这篇关于如何让django管理控制台URL优先?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!