[Django]-Why is my form always unbound?

5👍

What is happenning here is that UserForm uses the first argument (user) to initalize its internal state, so it doesn’t pass anything to forms.Form. To get the expected behaviour, you can pass an extra argument:

>>> f = UserForm(None, {})
>>> f.is_bound
True

12👍

Your __init__ statement is swallowing the first argument.

Remove user=None from your init statement, and perhaps pull it from the kwargs instead.

class UserForm(forms.Form):
    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user', None)
        super(UserForm, self).__init__(*args, **kwargs) 
        # now the form is actually receiving your first argument: args[0] == {}

Leave a comment