Situation: I have a form that is used for search, and I return the same form on the results page so that the user can filter their results. To get rid of garbage input, I used the clean_xxx method.
Unfortunately, the form returns on the garbage input page even if it has been cleared. How can I display clean data?
Here are some ideas:
- In the clean_xxx method, set the value self.data.xxx = cleaned_xxx
- Re-initialize the new form with cleaned_data.
forms.py:
SearchForm: def clean_q(self): q = self.cleaned_data.get('q').strip()
views.py
search_form = SearchForm(params, user=request.user) if search_form.is_valid():
Thank you for your help.
Naqeeb
source share