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>&#39;postform&#39; object has no attribute &#39;cleaned_data&#39;</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

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -