Django form_valid () and form_invalid () in CreateView are not called

I am currently using django CreateView to publish data to a database. Unfortunately, the method in which I would like to save and execute user logic, form_valid () is never called. I read in another answer about stack overflows that form_invalid () might solve the problem, but I can't get this method to call either. The only method that seems to call is get (), which I overridden and inserted the print statement. What am I doing wrong?

class declaration in view.py

class TeamCreate(CreateView): # Manipulate and use this Method instead of create_team model = Team # form_class = create_team_form fields = ['team_name', 'sport', 'sport_season'] success_url = '/' def get(self, request, *args, **kwargs): self.user = request.user print 'happening1' return super(TeamCreate, self).get(request, *args, **kwargs) def form_valid(self, form): print 'happening2' # form.instance.save() # self.user.teams.add(form.instance) form.save() return super(form_valid, self).form_valid(form) def form_invalid(self, form): print "form is invalid" return http.HttpResponse("form is invalid.. this is just an HttpResponse object") 

corresponding template code

 {% block content %} <form action="" method='POST'> {% csrf_token %} {{ form|crispy }} <input class="btn btn-primary" type="submit" value="Create" /> </form> 
+7
source share
2 answers

Apparently, the quotes around POST were not quotes at all, but hidden ninjas that destroy characters. "vs". I'm going to sleep.

+26
source

try it

 <form action="" method="post"> 
+3
source

All Articles