フォームを送信しようとすると、次のエラーが発生します。
argument of type 'NoneType' is not iterable
私のフォームクラスは次のとおりです。
class requestform(ModelForm):
def __init__(self, *args, **kwargs):
super(requestform, self).__init__(*args,**kwargs)
self.is_update=False
requestedpart = forms.CharField (label="Requested Part", max_length=80, required= True)
librarytype = forms.TypedChoiceField (label="Type", choices = ((1, "Type1"), (2, "Type2"), (3, "Type3")), coerce = lambda x: bool(int(x)), widget = forms.RadioSelect, required= True)
requestformat = forms.TypedChoiceField (label="Format", choices = ((1, "Format1"), (2, "Format2")), coerce = lambda x: bool(int(x)), widget = forms.RadioSelect, required= True)
def clean(self):
if 'requestedpart' not in self.cleaned_data:
return
if not self.is_update:
return self.cleaned_data
class Meta:
model = LibraryRequest
私の見解は次のとおりです
if request.method == "POST":
formtoaddrequest = requestform(request.POST, request.FILES)
if requestform.is_valid(formtoaddrequest):
new_request = formtoaddrequest.save(commit=False)
new_request.requestadder = request.user
new_request.save()
request.user.message_set.create(message=_("You have saved '%(requestedpart)s'") % {'requestedpart': new_request.requestedpart})
これが私のトレースバックです
Traceback:
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
100. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/AB/Desktop/store/project/views.py" in view_requests
201. if formtoaddmodel.is_valid():
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/forms.py" in is_valid
121. return self.is_bound and not bool(self.errors)
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/forms.py" in _get_errors
112. self.full_clean()
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
269. self._post_clean()
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/models.py" in _post_clean
316. self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude)
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/models.py" in construct_instance
40. or not f.name in cleaned_data:
Exception Type: TypeError at /project/view_requests/
Exception Value: argument of type 'NoneType' is not iterable
なぜこのエラーが発生するのかについての洞察はありますか?