I have the following view which extends the base CreateView:
class PeopleImportCsv(FailedLoginMessageMixin, CreateView):
model = CsvFile
form_class = CustomerCsvImportForm
template_name = 'people/customer_uploadcsv_form.html'
def get_success_url(self):
url = reverse('customer_process_csv', args=[self.object.id])
return url
def form_valid(self, form):
instance = form.save(commit=False)
instance.uploaded_by = self.request.user
super(PeopleImportCsv, self).form_valid(form)
I am using the get_success_url() method so I can get the id of the newly created object in the database. However, when I attempt to submit my form I get the following ValueError message:
The view people.views.PeopleImportCsv didn't return an HttpResponse object.
If I place an assert False
immediately after assigning the url in get_success_url() then I can see that it has the correct url I'm expecting so what can I do to sort this out?
You need to have a return
from the form_valid
method (if you are using a ModelForm
):
def form_valid(self, form):
instance = form.save(commit=False)
instance.uploaded_by = self.request.user
return super(PeopleImportCsv, self).form_valid(form)
You can see the methods signature in the Django source
P.S There is a very useful site for referencing Djangos many class based views here: http://ccbv.co.uk/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With