How to check if a user is logged in (how to properly use user.is_authenticated)?

后端 未结 6 1854
挽巷
挽巷 2020-11-28 01:17

I am looking over this website but just can\'t seem to figure out how to do this as it\'s not working. I need to check if the current site user is logged in (authenticated),

6条回答
  •  长情又很酷
    2020-11-28 01:48

    In your view:

    {% if user.is_authenticated %}
    

    {{ user }}

    {% endif %}

    In you controller functions add decorator:

    from django.contrib.auth.decorators import login_required
    @login_required
    def privateFunction(request):
    

提交回复
热议问题