I have defined choices for a category in models.py which is being referenced in forms.py like so:
models.py
class Exp(models.Model):
CATEGORIES = ( ('Inc', 'Inc'),\
('Hom', 'Hom'),\
('syn', 'Syn'),\
('Was', 'Was')\
)
forms.py
class ExpForm(ModelForm):
category = forms.MultipleChoiceField(choices=Exp.CATEGORIES, widget=forms.CheckboxSelectMultiple())
class Meta:
model = Exp
views.py
def view_exp(request):
if request.method == "POST":
form = ExpForm(request.POST)
if form.is_valid():
...
The multiselect choice is displayed correctly in the form, but when I select multiple options, the form.is_valid()
in views.py
is returning false with a AttributeError: 'str' object has no attribute 'status_code
error. I understand that I am getting a str
instead of an HttpResponse
object, but can't figure out how to fix this error. Any help is appreciated.
NOTE: There are other fields in the same form which are of type CharField
.
Here is the traceback:
Traceback (most recent call last):
File "/software/python/python-2.7.3/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in get_response
response = middleware_method(request, response)
File "/software/python/python-2.7.3/lib/python2.7/site-packages/django/middleware/common.py", line 106, in process_response
if response.status_code == 404:
AttributeError: 'str' object has no attribute 'status_code'