2👍
✅
I think the reason why the data isn’t being given to the form is because you have overridden the get_form
method without passing it the request.POST
data. Instead of overriding that method, I think it’s more appropriate to override the get_form_kwargs
method instead.
class CleanTeamMainContactView(LoginRequiredMixin, FormView):
template_name = "cleanteams/main_contact.html"
form_class = EditCleanTeamMainContact
success_url = "mycleancity/index.html"
def get_initial(self, clean_team_member):
...
def get_form_kwargs(self):
clean_team_member = self.request.user.profile.clean_team_member
kwargs = {
"initial": self.get_initial(clean_team_member),
"clean_team": clean_team_member.clean_team
}
if self.request.method in ("POST", "PUT"):
kwargs.update({
"data": self.request.POST,
"files": self.request.FILES
})
return kwargs
def form_invalid(self, form, **kwargs):
...
def form_valid(self, form):
...
This should hopefully fix the empty form.data
issue but I’m not sure if the form will still be invalid or not.
Source:stackexchange.com