How to debug this stracktrace in django?

I have a form inside a modal, when I click save I get the following error. The issue is that I dont know where to find it because it’s not showing that the error is in my code.


Request Method: POST
Request URL: http://localhost:8000/user/add/

Django Version: 3.1.3
Python Version: 3.9.0
Installed Applications:
Installed Middleware:

Traceback (most recent call last):
  File "", line 47, in inner
    response = get_response(request)
  File "", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)

Exception Type: TypeError at /user/add/
Exception Value: __init__() takes 1 positional argument but 2 were given

urls – it’s a form view

urlpatterns = [
    path('add/', views.AddUserFormView, name='add-user'),

the form view does the post request logic

class AddUserFormView(FormView):
    form_class = TbUserAddForm
    template_name = 'users/add_user_modal.html'
    def post(self, request):
        form = self.form_class(request.POST, request.FILES)
        if form.is_valid():
            user_face_img_md5 =
            user_head_img_md5 =
            obj =
            response = addUserApi(obj.__dict__,
                                  user_face_img_md5, user_head_img_md5)
            print(f"Request Response [Add User] --> {response.text}")
            return redirect('add-user')

and the form, i think here is the problem with the init. When I instantiate the form, i give the request.POST and request.FILES

class TbUserAddForm(CustomUserCreationForm):

    def __init__(self, user, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.user = user
        if self.user:
            self.fields['role'].queryset = TbRole.objects.all().filter(
            self.fields['department'].queryset = TbDepartment.objects.all().filter(

    class Meta:
        model = TbUser
        fields = [...]


When you use class-based views in django, you should tell django behave to your class-based view as view in

urlpatterns = [
    path('add/', views.AddUserFormView.as_view(), name='add-user'),

Be aware that your not passing user to your TbUserAddForm, it would be your next bug probably:

form = self.form_class(request.user, request.POST, request.FILES)