title: CSRF token missing or incorrect, when sending request across 2 different apps
body: <p>I am new to django, I am sending a form data from my index.html(1st app 's template) file to accounts app's(another app) views.py</p>
  
  <p>index.html - app01/templates</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;hello&lt;/title&gt;
  
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"&gt;
  
  
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"&gt;
  
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"&gt;&lt;/script&gt;
  
  &lt;style type="text/css"&gt;
      body{
          background-color: 'lightblue';
      }
  &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;nav class="navbar navbar-inverse bg-faded"&gt;
  &lt;a class="navbar-brand" href="#about"&gt;
  &lt;img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Cyno_Small_Logo_(Aug._2015).png/240px-Cyno_Small_Logo_(Aug._2015).png" width="30" height="30" &gt;
  
  &lt;/a&gt;
  &lt;div class="col-md-2 bg-warning"&gt;&lt;h3&gt;Quizapp&lt;/h3&gt;&lt;/div&gt;
  
  &lt;div class="container off col-md-offset-2"&gt;
      &lt;ul class="nav nav-tabs"&gt;
           &lt;li&gt;&lt;a data-toggle="tab" href="#regtab"&gt;New User? Register here!&lt;/a&gt;&lt;/li&gt;  
          &lt;li&gt;&lt;a data-toggle="tab" href="#logtab"&gt;Already have an account? Login!&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/nav&gt;
      &lt;div class="tab-content"&gt;
          &lt;div id="regtab" class="tab-pane fade text-primary"&gt;
  
  
      {% csrf_token %}
  
          {{ rform }}
  
  
  
      &lt;button id="rbtn" type="button" class="btn btn-primary btn-lg "&gt;Register!&lt;/button&gt; 
          &lt;/div&gt;
          &lt;div id="logtab" class="tab-pane fade text-success" data- loading-text="Registering"&gt;
  
      {% csrf_token %}
  
          {{ lform.as_p }}
  
  
  
          &lt;button id="lbtn" type="button" class="btn btn-primary btn-lg         " data-loading-text="Logging in" &gt;Login!&lt;/button&gt; 
          &lt;/div&gt;
      &lt;/div&gt;
   &lt;/div&gt;
  
  
  
  
  &lt;script type="text/javascript"&gt;
  
  $('#rbtn').click(function(){
      var form_data = {
          'username' : $('#id_username').val(),
          'password' : $('#id_password').val(),   
          'name' : $('#id_name').val()
      }
      $.post('/register_data/',form_data,function (data, status){
          var dt = JSON.parse(data);
          var reg_status = dt.data.status;
          if(reg_status == 'success'){
              alert("registered! click Ok to go to home");
              window.location = '/';
          }
          else{
              alert("check form bro!");
          }
  
      });
  });
  
  &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>views.py - accounts </p>
  
  <pre><code>from django.shortcuts import render,redirect    
  from django.http import HttpResponse
  from django.views.decorators.csrf import csrf_exempt    
  from app01.models import LoginForm,RegisterForm
  from django.contrib.auth import authenticate, login, logout
  from django.contrib.auth.decorators import login_required
  import json
  @csrf_exempt
  def register_data(request):
      resp = {
          'status': ''
      }
  
      if not request.method == 'POST':
          resp['status'] = 'post req pls'
          return HttpResponse(json.dumps({'data': resp}))
  
      frm = RegisterForm(request.POST)
  
      if frm.is_valid():
  
          uname = frm.cleaned_data['username']
          ps = frm.cleaned_data['password']
          name = frm.cleaned_data['name']
          try:
              usr= User(username=uname)
              usr.set_password(ps)
              usr.save()
  
  
          except:
              resps['status']='user already exists'
              return HttpResponse(json.dumps({'data':resp}))
  
          myusr = MyUser(user=usr,name=name)
          myusr.save()
          return redirect('/')
          resp['status'] = 'success'
          return HttpResponse(json.dumps({'data':resp}))
  </code></pre>
  
  <p>Everytime I click the register button, the terminal returns 403 Forbidden Error, CSRF token missing or incorrect. I have already included {%csrf_token%} before form and also @csrf_exempt before the function. </p>
  
  <p>The code is still under development (login function yet to be made), I am stuck until this register page sends request to the views.py/register_data</p>