我已创建用户并尝试登录,然后弹出此错误。 “ NoneType”对象不可调用

我收到类似上面标题的错误。我不在哪里。这是views.py的代码 我已经创建了用户,当我尝试登录用户时,该错误弹出窗口。我正在努力摆脱昨天的麻烦。我正在使用信号法

from django.http import HttpResponse
from django.shortcuts import redirect

def admin_only(view_fun):
     def wrapper_function(request, *args, **kwargs):
         group = None
         if request.user.groups.exists():
              group = request.user.groups.all()[0].name
          if group == 'customer':
              return redirect('user')
           if group =='admin':
               return view_fun(request, *args, **kwargs)
           return wrapper_function

这是views.py的代码。我从昨天开始调试。

from django.shortcuts import render,redirect
from django.http import HttpResponse
from django.template import RequestContext
from django.forms import inlineformset_factory  
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login as dj_login, 
                                 logout
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group
from account.models import *
from account.forms import OrderForm, CreateUserForm, 
                           CustomerForm
 from account.filters import OrderFilter
 from account.decorators import unauthenticated_user, 
                            allowed_users, admin_only
 @login_required(login_url='login')
 @admin_only
 def dashboard(request):
     orders = Order.objects.all()
     customers = Customer.objects.all()
     total_customer = customers.count()
     total_order = orders.count()
     delivered = orders.filter(status = 'Delivered').count()
     pending = orders.filter(status = 'Pending').count()

     context= 
             {'orders':orders,'customers':customers,
               'total_order':total_order,
               'delivered':delivered,'pending':pending}
     return render(request,'account/dashboard.html',context)
评论