title: I had 'NoneType' object has no attribute 'groups' in django
body: <p>I'm new in django,I just have the error, AttributeError at /registro/ 'NoneType' object has no attribute 'groups', but my form is saving all the data</p>
  <p>views.py</p>
  <pre><code>def register(request):
      if request.method == 'POST':
          form = CreateUserForm(request.POST)
          
          if form.is_valid():
              ui = User()
              ui.username = request.POST.get('username')
              ui.password = request.POST.get('password')
              ui.first_name = request.POST.get('first_name')
              ui.last_name = request.POST.get('last_name')
              ui.email = request.POST.get('email')
              # user = User.objects.create_user(username=username,first_name=first_name,last_name=last_name,email=email,password=password)
              user = ui.save()
              obj = User.objects.latest('id')
              cli = Client_profile_master()
              cli.first_name = request.POST.get('first_name')
              cli.last_name = request.POST.get('last_name')
              cli.email = request.POST.get('email')
              cli.mobile_no = request.POST.get('mobile')
              cli.address_1 = request.POST.get('address1')
              cli.address_2 = request.POST.get('address2')
              cli.image=request.FILES.get('image')
              cli.user=obj
              # emp.save()
              # client = Client_profile_master.objects.create(first_name=first_name,last_name=last_name,email=email,mobile=mobile,address1=address1,address2=address2,image=image,user=obj)
              cli.save()
              username = form.cleaned_data.get('username')
              group = Group.objects.get(name='Client')
              user.groups.add(group)
  
              messages.success(
                  request, f'Account created successfully for {username} !!!')
              return redirect('login')
          else:
              return redirect('/')
      else:
          form = CreateUserForm()
      return render(request, 'sites/register.html', {'form': form})
  </code></pre>