Is there a built-in login template in Django?

前端 未结 6 1815
臣服心动
臣服心动 2020-12-12 11:48

I want to let a user sign in before seeing pages. Is there any built-in template for user sign in, so that I do not have to write my own sign in page?

6条回答
  •  一向
    一向 (楼主)
    2020-12-12 12:13

    Similar to mrts’ answer, in more recent Django, you can use the LoginView. You can further customize the template by setting template context like title, site_title etc. as used in admin/base.html so that it doesn’t look like an admin login.

    from django.contrib.auth.views import LoginView
    
    urlpatterns = [
        url(  
            r'^accounts/login/$',  
            LoginView.as_view(
                template_name='admin/login.html',
                extra_context={         
                  'title': 'Login',
                  'site_title': 'My Site',
                  'site_header': 'My Site Login'},
            name='login'),
    ]
    

提交回复
热议问题