I'm logged in. why display NOT LOGIN!
in html?
VIEWS
from django.contrib.auth.mixins import LoginRequiredMixin
class UserHomeView(LoginRequiredMixin, ListView):
model = User
template_name = 'users/users_index.html'
paginate_by = 10
context_object_name = 'user'
def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
return context
HTML
{% if user.is_authenticated %}
LOGIN!
{% else %}
NOT LOGIN!
{% endif %}
setting.py
LOGIN_URL = '/users/login/'
try this {% if request.user.is_authenticated %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.