curl -d sends data using POST method, not GET method (see curl
documentation). Django expects CSRF token in all POST requests, check
http://docs.djangoproject.com/en/dev/ref/contrib/csrf/
HTH
Jirka
You can mark things as exempt if you'd like to and are aware of the implications:
http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#exceptions
--
Andy McKay
an...@clearwind.ca
twitter: @andymckay
How do I add CSRF token to curl then?
What if I wanna expose my views as web services without providing a
UI, how do I make sure clients (e.g. Ajax, actionscript, etc) can use
it without this CSRF issue?
Thanks.
> Is there a way to completely disable CSRF handling?
Sure, just remove the CSRF middleware from your settings.py.
While this advice is 100% accurate, I'd would *strongly* caution you
not to follow it.
If someone has a problem losing their house keys, the solution isn't
to remove your front door. Yes, removing the door does remove the need
for keys, but also leaves your house open to the weather, animals,
criminals, and so on. The fix, while it does solve the immediate
problem, makes the overall situation much worse.
Django's CSRF framework exists, and is enabled by default, for a
reason. CSRF attacks are both real and common, and defence against
CSRF is an important part of any serious web deployment.
If you're having difficulty with CSRF, the solution isn't to disable
CSRF. The solution is to work out what CSRF protection means, and how
to use it correctly. Although it's a little esoteric, and a little
unusual if you've come from a web framework that doesn't enforce good
security practices, it isn't *that* hard to use. You would be well
served to understand what is going on, rather than making the CSRF
problem go away by ignoring it.
Yours,
Russ Magee %-)
The CSRF token is just a hidden field on your form. When you render
your template, the CSRF token will be included on the rendered page.
Include that token as part of your post data as you would any other
field value.
Yours,
Russ Magee %-)