Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django dev server unread POST data will error

Tags:

python

django

I have the solution, this is more of a Why question. The problem is when running a django dev server, when i make an ajax POST request with data, if the view never looks at the POST dict, i get a urllib2 exception. "a connection was forcibly closed by a remote host" or something.

If theres no post data, it returns fine, if the data is read, not even stored, a simple

request.POST

will return ok as well. Why is this?

Thanks

like image 372
Brett Avatar asked Apr 27 '26 21:04

Brett


1 Answers

I'm guessing you're not sending the csrfmiddleware_token on your post request. It's a prevention mechanism for CSRF attacks and needs to be set on all POST messages. See the documentation for details.

like image 186
jeffknupp Avatar answered Apr 29 '26 09:04

jeffknupp