Authentication django

问题: Why is self.request.user.is_authenticated() not working in this view? class ArticleDetailView(DetailView, CategoryListMixin): model = Article template_name = 'mai...

问题:

Why is self.request.user.is_authenticated() not working in this view?

class ArticleDetailView(DetailView, CategoryListMixin):
    model = Article
    template_name = 'mainapp/article_detail.html'

    def get_context_data(self, *args, **kwargs):
        context = super(ArticleDetailView, self).get_context_data(**kwargs)
        context['articles'] = self.model.objects.all()
        context['article'] = self.get_object()
        context['comments'] = Comments.objects.filter(article=context['article']).order_by('-pub_date')
        if self.request.user.is_authenticated():
            context['current_user'] = PersonalAccount.objects.get(user=self.request.user)
        return context

I got an error:

'bool' object is not callable


回答1:

For Django 1.10 +

is_authenticated is now an attribute.

if self.request.user.is_authenticated:
  • 发表于 2019-03-18 23:23
  • 阅读 ( 131 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除