I've been looking for few days now how to convert form submissions to ajax with jquery, and the csrf token issue is puzzling me.
I solved the problem by adding the javascript snippet found here : https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
But when stumbling on stackoverflow, I found simpler answers (not the first one): Django CSRF check failing with an Ajax POST request
Some answers suggest to simply add the following to the post data: csrfmiddlewaretoken: '{{ csrf_token }}'
But this seems too good to be true, if that was that easy, why would we need to copy the long snippet from the django website ? Also there's a quick comment to one of the replies about static JS. I don't really get it.
Could anyone please explain why the simplest solution isn't the best, and give some practical examples ?
Thanks