python - Django code only works in debug -
very confused one. code in views.py works, when i'm debugging using pycharm. if runserver 500 error.
views.py:
def add_post(request): if request.method == 'post': form = postform(request.post) cd = form.cleaned_data if form.is_valid(): print "valid" post = post(nickname=cd['nickname'], body=cd['body'], category=cd['category']) post.save() return httpresponse("success") return httpresponseservererror("fail") error seen in chrome inspector
<th>exception value:</th> <td><pre>'postform' object has no attribute 'cleaned_data'</pre></td> no attribute cleaned_data? why...?
the cleaned_data attribute becomes available after calling is_valid() on form. should move cd = form.cleaned_data below if.
Comments
Post a Comment