Django: Model Form “object has no attribute 'cleaned_data'”

后端 未结 3 899
星月不相逢
星月不相逢 2020-12-22 17:51

I am trying to make a search form for one of my classes. The model of the form is:

from django import forms
from django.forms import CharField, ModelMultiple         


        
3条回答
  •  时光取名叫无心
    2020-12-22 18:01

    For some reason, you're re-instantiating the form after you check is_valid(). Forms only get a cleaned_data attribute when is_valid() has been called, and you haven't called it on this new, second instance.

    Just get rid of the second form = SearchForm(request.POST) and all should be well.

提交回复
热议问题