Simple javascript to make easy to make POST with AJAX using Django. Based on django documentation.
- Add
CsrfViewMiddleware
in yourMIDDLEWARE_CLASSES
insettings.py
file of your project.
MIDDLEWARE_CLASSES = (
...
'django.middleware.csrf.CsrfViewMiddleware',
...
)
- Add the javascript file
https://raw.github.com/ebertti/js-csrf-django/master/csrf.js
in thehead
of your html page, rather in youtbase.html
, after jQuery file:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<scripr scr="https://raw.github.com/ebertti/js-csrf-django/master/csrf.js"></script>
</head>
</html>
- Now you can make your AJAX request using POST.