我如何使用LoginRequiredMixin在基于类的视图中引发django错误消息?

I have a class based view ProfileView to which unauthorized users are not allowed access to. I have used the LoginRequiredMixin to limit access.

class ProfileView(LoginRequiredMixin, TemplateView) :
     template_name='profile.html'
     permission_denied_message='You are not allowed access here' 
     login_url='/users/login'

I have this snippet included in my base.html

{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">
{{ message }}
</div>
{% endfor %}
{% endif %}

但是,当我尝试以匿名用户身份登录时,我被重定向到登录URL,但是没有显示任何消息。我该怎么办?

评论