2
For Js:
$("form").submit(function() {
$.ajax({
url: '{% url home %}',
data: {selected_folders: formData,
csrfmiddlewaretoken: $("[name = csrfmiddlewaretoken]"),
dataType: "json",
type: "POST",
});
});
For view.py:
def home(request):
if request.method == 'POST' and request.is_ajax():
Call_Other_Class()
return render_to_response('home.html')
0
The best solution is using the online documentation.
From what I recall:
- first call a GET in Ajax and in the answer, force
ensure_csrf_cookie
decorator - then keep the CSRF cookie, you have all the detail explanation here.
- [Answered ]-Django, showing only matches condition in lookup
- [Answered ]-Can't delete user after removing app
- [Answered ]-Django model query tune up
- [Answered ]-Class Based View, add data to the Form
- [Answered ]-Django dynamically choose a foreign key relation model
Source:stackexchange.com