1

我想将 django admin 的默认 url 从 /admin 更改为 /djadmin,以便我可以将 /admin 用于我自己的目的。

到目前为止,我所做的只是更新 urls.py 文件,将管理 url 更改为

url(r'^djadmin/', include(admin.site.urls)),

然后添加我自己的

(r'^admin/', include('my_app.admin_urls')),

但是,当我现在导航到 /admin 时,出现以下错误

Forbidden

You do not have staff privileges.

因为我不需要这个参数,所以我假设它来自内部 django 检查。如果我将用户更改为is_staff检查标志,那么它可以正常工作并重定向到我的管理页面。

is_staff每当我导航到管理网址时,我还需要做些什么来阻止 Django 检查标志吗?

4

1 回答 1

0

The is_staff flag is wrapped in the code of Django admin site, because is intended to restrict the usage of this interface only to a subgroup of selected users (the ones that administrate the content of the website). The only way to remove it is to subclass the Django's admin site, so a your own custom site.

For admin site customization see the official documentation or other answers like the one I've posted previously. In the AdminSite subclass you have to override the has_permission method with:

def has_permission(self, request):
   return request.user.is_active

You also need to use a custom admin form (AdminSite.login_form) and modify the base.html template, removing references about is_staff in a pair of if statements.

于 2013-06-26T08:42:19.930 回答