[Django]-Curious about get_form_kwargs in FormView

35👍

The get_form_kwargs method will return a dictionary with the kwargs that will be passed to the __init__ of your form. Now, if you have a form that expects a kwarg named user and pass it a kwarg named request it will complain with the error you see. If you want to pass request instead of user (this is what I usually do since the request contains the user) then you should define your form class like this:

class RequestForm(forms.Form):
    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(RequestForm, self).__init__(*args, **kwargs)

Leave a comment