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] == {}
- [Django]-Searching for a project skeleton for Chef + Django on Linux
- [Django]-How to filter generic foreign keys?
- [Django]-Django Channels stops working with self.receive_lock.locked error
- [Django]-Django ORM – Grouped aggregates with different select clauses
Source:stackexchange.com