I am new to Django and working on a small project where a JQuery client sends a JSON request (username and password) to my DJango server page. But, Django spits out a 403 error every time. This is the error I get:
POST /html/localhost HTTP/1.1" 403 2326
This is frustrating as it is a very basic setup that involves client <-> server communication.
My client-side form:
<form id="loginForm" action="vs.djangoserver" method="post">
User: <input type="text" name="username" />
Pass: <input type="password" name="password" />
<input type="submit" value="Submit" />
vs.djangoserver is mapped correctly (or so I think), and I can navigate to it using Django's test server.
The JQuery code that sends the form's fields as JSON is here:
$.ajax({
type: "POST",
url: formAction,
data: printableJSONStr,
dataType: "json",
beforeSend: function(x,y) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
success: post_submit
});
What I am confused about is how to POST to a page that Django creates and serve on the fly. I am awre of Django's CSRF protection, and I added this to my Django's view:
from django.views.decorators.csrf import
@csrf_exempt
def .......
One other thing I tried was to point to a non-existent action in the client form. In that case, I got the same 403 error (versus a 404 as I expected).
I am looking for a simple (but complete) example where JQuery points to a django's page and it works!