Can the Admin UI be used without the user authenti

2019-06-27 23:46发布

问题:

I was wondering if there's an easy way to configure the Django Admin UI (eg at http://mysite.com/admin) so that I don't need to authenticate/login?

I've tried tweaking urls.py but couldn't get it to bypass the login screen:

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

I'd like to go to http://mysite.com/admin and see the list of django objects without having to login.

Thanks.

回答1:

  • Django admin framework uses 'is_staff' flag on the 'User' object to verify the permission to use admin site.
  • So it needs an user to be authenticated to verify his admin related permissions.
  • If you want to disable this, you have to override the 'index' method of the admin site.
  • It is available at django.contrib.admin.sites.

def index(self, request, extra_context=None):

     """
     Displays the main admin index page, which lists all of the installed
     apps that have been registered in this site.
     """