django if语句适用于一个但不适用于另一个

时间:2016-02-22 16:45:03

标签: python django

我正在尝试在我的视图中使用if else语句,所以当我签​​名时,管理员和当我注销客户端时。它适用于我的queryset_list但不适用于名称。继承我的代码

def post_list(request):
  today = timezone.now().date()
  queryset_list = Post.objects.active()
  if request.user.is_staff or request.user.is_superuser:
      queryset_list = Post.objects.all()

  paginator = Paginator(queryset_list, 8)
  page_request_var = 'page'
  page = request.GET.get(page_request_var)
  try:
    queryset = paginator.page(page)
  except PageNotAnInteger:
    queryset = paginator.page(1)
  except EmptyPage:
    queryset = paginator.page(paginator.num_pages)
  template = "posts/post_list.html"
  name = "client"
  if request.user.is_staff or request.user.is_superuser:
    name = "admin"
  count = queryset_list.count()
  so = name
  hey = paginator.num_pages
  context = {
      "object_list": queryset,
      "name": so,
      "page_request_var": page_request_var,
      "today": today,
      "count": count,
      "paginator": paginator,
      "hey": hey
  }

0 个答案:

没有答案