Putting a django login form on every page

后端 未结 4 921
执念已碎
执念已碎 2020-11-27 11:35

I\'d like the login form (AuthenticationForm from django.contrib.auth) to appear on every page in my site if the user is not logged in. When the user logs in, they will be r

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 11:53

    Using django.contrib.auth, you can put the form code in the base template like so:

    {% csrf_token %}

    All you need to do is modify the next value so instead of:

    
    

    It will now be:

    
    

    To access the request object, make sure you include

    'django.core.context_processors.request'
    

    in your template context processors. This way you don't have to write any context processors for logins since you are using the Django built-in views.

提交回复
热议问题