Add CSRF helpers to Django.js#9
Conversation
|
@cpdean added tests |
|
Interesting! Right now the tests fails on Django 1.5 because the csrf_token template tag is no longer enclosed in a div. In Django 1.4: <div style="display:none"><input type="hidden" name="csrfmiddlewaretoken" value="YYB0aBXCinye9jZbmkvkSWvc1zQ4aRjg"></div>In Django 1.5: <input type="hidden" name="csrfmiddlewaretoken" value="7GPRlZilh1swRp3VPtGzPdu3EyhYNtGk">I think the important part is the input, not the outer div. Why not change the test to only test the input: var $csrfTag = $('#test-csrf-elem input[name="csrfmiddlewaretoken"]');In the documentation, instead of saying "return the element containing the CSRF token, as if you'd used the Just forget the outer div. Fix it and rebase, I'll merge it ASAP (when tests passes). |
|
I didn't think to check the 1.5 docs, I figured there was a reason Django included the |
`Django.csrf_token();` returns the value of the CSRF token.
`Django.csrf_element();` returns an element containing the CSRF token,
as if you were to use `{% csrf_token %}`.
Add CSRF helpers to Django.js
|
Thanks |
Django.csrf_token();returns the value of the CSRF token.Django.csrf_element();returns an element containing the CSRF token,as if you were to use
{% csrf_token %}.The primary purpose of this is for creating non-AJAX forms with Javascript rather than Django Forms.