This a the class (in Django 1.7.4) I do not understand... in the form_valid() function:
class ImportCsv(FormView):
template_name = "backend/import.html"
form_class = UploadFileForm
success_url = reverse_lazy("b_import_csv")
csverrors = []
def get_context_data(self, **kwargs):
ctx = super(ImportCsv, self).get_context_data(**kwargs)
ctx.update({
"csverrors" : self.csverrors,
})
return ctx
def form_valid(self, form):
self.csverrors.append("Yeah")
self.template_name+="yeah"
return super(ImportCsv, self).form_valid(form)
This class just shows what I cannot understand: once the form is valid, form_valid() is called. There I change two things: self.csverrors and self.template_name.
Then I reload my page: the template name is still the original one, but csverrors remembers the "Yeah". I can submit the form again and again: csverrors keeps growing. The point is: I can change also self.form_class and self.success_url, but everything will be restored in the next connection. Why csverrors is still there?
I cannot see the differences between those two variables and why they act differently. I know the function get_gemplate_names() in this particular case, but this is a general question about instance variables.
The goal was just to put something in an instance variable and change get_success_url() accordingly to that variable. Problem: that variable will not go away.