How to bring default add user page at django custo

2019-08-09 04:59发布

问题:

When I use django's default admin page:

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

The add user page looks pretty like this...

But when I use my own:

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

class StripeAdminSite(admin.AdminSite):
    def index(self, request, extra_context=None):
          return todo

and

django.auth.contrib.models.User

registered to the site

stripe_admin_site.register(User)

I got this

Now how can I make it look like the default, easily?

回答1:

Simply register the User model with the same ModelAdmin that Django uses by default:

from django.contrib.auth.admin import UserAdmin
stripe_admin_site.register(User, UserAdmin)