Friday, March 18, 2011

how to get csrf cookie in ajax app

In an ajax-based site, where the page is static, and makes ajax calls
after loading, how would one get a csrf cookie? There aren't any
templates associated with the views (they just return json strings).
Setting of the cookie seems to be a side effect of serving forms in
django, but the client doesn't need to fetch a form from the server
for ajax calls. render_to_response finds a reference to the csrf in
the template, calls some internal function to retrieve the csrf, which
sets some flag causing the csrf middleware to add the set-cookie to
the response. Or something?

So, for an ajax app, I could create a view with an empty form,
including just the csrf? Or create a view that calls get_token()?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate