Saturday, August 30, 2014

Re: how to call django web page with ordinary html page

If it helps, you can read/set the csrf cookie using javascript. here's some rough code:

  if(!document.cookie.match('csrftoken=([a-zA-Z0-9]{32})')){
   
for(var c = ''; c.length < 32;) c += Math.random().toString(36).substr(2, 1)
    document
.cookie = 'csrftoken=' + c + '; path=/'
 
}
  document
.write('<input type="hidden" name="csrfmiddlewaretoken" value="' + document.cookie.match('csrftoken=([a-zA-Z0-9]{32})')[1] + '">')

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e696027d-09ef-4b6a-8e59-dc7c441020e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment