How to resolve "TypeError: __init__() missing 1 required positional argument: 'user'" in django?

class AjaxUpdateView(AjaxMixin, UpdateView):
“”" An ‘AJAXified’ UpdateView for updating an object in the db
- Returns form in JSON format (for delivery to a modal window)
- Handles repeated form validation (via AJAX) until the form is valid

        def get(self, request, *args, **kwargs):
            """ Respond to GET request.

            - Populates form with object data
            - Renders form to JSON and returns to client

            super(UpdateView, self).get(request, *args, **kwargs)
            return self.renderJsonResponse(request, self.get_form(), context=self.get_context_data())

        def post(self, request, *args, **kwargs):
            """ Respond to POST request.

            - Updates model with POST field data
            - Performs form and object validation
            - If errors exist, re-render the form
            - Otherwise, return sucess status

            # Make sure we have an object to point to
            self.object = self.get_object()

            form = self.get_form()

            data = {
                'form_valid': form.is_valid()

            if form.is_valid():
                obj =

                # Include context data about the updated object
                data['pk'] =

                    data['url'] = obj.get_absolute_url()
                except AttributeError:

            return self.renderJsonResponse(request, form, data)

class SetPasswordForm(HelperForm):
enter_password = forms.CharField(max_length=100, required=True,
widget=forms.PasswordInput(attrs={‘autocomplete’: ‘off’}))
confirm_password = forms.CharField(max_length=100, required=True,
widget=forms.PasswordInput(attrs={‘autocomplete’: ‘off’}))

        class Meta:
            model = User
            fields = [

        def clean(self):
            cleaned_data = super(SetPasswordForm, self).clean()
            enter_password = cleaned_data.get("enter_password")
            confirm_password = cleaned_data.get("confirm_password")

            if enter_password != confirm_password:
                self.add_error('enter_password', " ")
                self.add_error('confirm_password', "Password does not match")

            return cleaned_data

Getting this error:-

        2020-04-09 13:00:37,648 ERROR Internal Server Error: /set-password/
        Traceback (most recent call last):
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/core/handlers/", line 34, in inner
            response = get_response(request)
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/core/handlers/", line 115, in _get_response
            response = self.process_exception_by_middleware(e, request)
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/core/handlers/", line 113, in _get_response
            response = wrapped_callback(request, *callback_args, **callback_kwargs)
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/views/generic/", line 71, in view
            return self.dispatch(request, *args, **kwargs)
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/views/generic/", line 97, in dispatch
            return handler(request, *args, **kwargs)
          File "/home/user/inventree/Inventorysolution/InvenTree/InvenTree/", line 313, in get
            super(UpdateView, self).get(request, *args, **kwargs)
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/views/generic/", line 190, in get
            return super().get(request, *args, **kwargs)
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/views/generic/", line 133, in get
            return self.render_to_response(self.get_context_data())
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/views/generic/", line 66, in get_context_data
            kwargs['form'] = self.get_form()
          File "/home/user/inventree/inventree-env/lib/python3.6/site-packages/django/views/generic/", line 33, in get_form
            return form_class(**self.get_form_kwargs())
        TypeError: __init__() missing 1 required positional argument: 'user'


Please format your code better in future posts, it’s hard to read with such broken highlighting.

The information you need is all in the error message and traceback. See “reading tracebacks” in .

The problem is that the form class you’re using takes a user argument. But the arguments it’s being passed don’t include user. Maybe youy can add it to the output of get_form_kwargs.

okay thanks, [adamchainz

Please reply on this thread if you know:- how can I also show stock message with there location like “Added %s items to stock with %s location”?