gpt4 book ai didi

django - 获取基于用户 ID 类的 View

转载 作者:行者123 更新时间:2023-12-04 13:10:34 25 4
gpt4 key购买 nike

如何获取登录到基于类的 View 中的用户的 ID?

这是我的 CBW

class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'
context = 'activate'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['activate'] = 'Polls'
return context

def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.exclude(panel__user='???',
panel__valid=False)
.order_by('-pub_date')[:5]

最佳答案

self.request.user :

  def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.exclude(panel__user=self.request.user,
panel__valid=False)
.order_by('-pub_date')[:5]

关于django - 获取基于用户 ID 类的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51632952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com