Django: How To Pre-populate Formview With Dynamic (non-model) Data?
I have a FormView view, with some additional GET context supplied using get_context_data(): class SignUpView(FormView): template_name = 'pages_fixed/accounts/signup.html' f
Solution 1:
You can override the FormView class's 'get_initial' method. See here for more info,
e.g.
defget_initial(self):
"""
Returns the initial data to use for forms on this view.
"""
initial = super().get_initial()
initial['my_form_field1'] = self.request.something
return initial
'get_initial' should return a dictionary where the keys are the names of the fields on the form and the values are the initial values to use when showing the form to the user.
Post a Comment for "Django: How To Pre-populate Formview With Dynamic (non-model) Data?"