Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery request to django gets 403 error even after disabling CSRF
    primarykey
    data
    text
    <p>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:</p> <pre><code> POST /html/localhost HTTP/1.1" 403 2326 </code></pre> <p>This is frustrating as it is a very basic setup that involves client &lt;-> server communication.</p> <p>My client-side form:</p> <pre><code>&lt;form id="loginForm" action="vs.djangoserver" method="post"&gt; User: &lt;input type="text" name="username" /&gt; Pass: &lt;input type="password" name="password" /&gt; &lt;input type="submit" value="Submit" /&gt; </code></pre> <p></p> <p>vs.djangoserver is mapped correctly (or so I think), and I can navigate to it using Django's test server.</p> <p>The JQuery code that sends the form's fields as JSON is here:</p> <pre><code> $.ajax({ type: "POST", url: formAction, data: printableJSONStr, dataType: "json", beforeSend: function(x,y) { if (x &amp;&amp; x.overrideMimeType) { x.overrideMimeType("application/j-son;charset=UTF-8"); } }, success: post_submit }); </code></pre> <p>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:</p> <pre><code>from django.views.decorators.csrf import @csrf_exempt def ....... </code></pre> <p>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).</p> <p>I am looking for a simple (but complete) example where JQuery points to a django's page and it works!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload