Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9144157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:12:03+00:00 2026-06-17T10:12:03+00:00

I am trying to use the $post request from javascript into my django template,

  • 0

I am trying to use the $post request from javascript into my django template, but there is something I am missing, since it is not working.

I will show you my code:

This is the template:

//TEMPLATE
//This code will send a string to django "views.py" file,
//then it will show a pop up message from the data retreived from "views.py"

function test_post(){ 
   $.post("/xhr_test", 
      {name: "Monty", food: "Spam", csrftoken : "{{ csrf_token }}" },

      function(data) {
          alert(data)
      ;}); 
};

This is the views.py:

// VIEWS.PY
//Depending on the type of request it will send a message or another.


def xhr_test(request):
    if request.is_ajax():
        if request.method == 'GET':
            message = "This is an XHR GET request"
        elif request.method == 'POST':
            message = "This is an XHR POST request"
            # Here we can access the POST data
            print request.POST
    else:
        message = "No XHR"
    return HttpResponse(message)

This code does not show the “This is an XHR POST request” message as it should. However it does show the “This is an XHR GET request” message when using the $get request.

A similar doubt was answer in this thread. Even though I am using the answers that were provided there, the code does not work.

I am guessing the answer must be related to the “{{ csrf_token }}”, but not sure how…

Any type of help will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:12:04+00:00Added an answer on June 17, 2026 at 10:12 am

    If this is due to csrf token (you can check it in your browser using firebug), then use this in your views.py

    from django.views.decorators.csrf import csrf_exempt
    
    @csrf_exempt
    def xhr_test(request):
       ...........
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send a POST request from iPhone to Django, but for some
I'm trying to use Mechanize to capture a POST request which is not possible
I'm trying to use spring rest template to do a post request. And i
Original Post: I am trying to use the Client-side Authentication with the Javascript SDK
I am trying to use javascript, without framework(prototype, jQuery,etc), to insert data passed from
I'm trying to use Zend_Http_Client to make a simple post request on a site
I am trying to make a post request on this page http://www2.gcitrading.com/quotes/converter.asp , but
I'm trying to send data through a POST request from a node.js server to
I'm making ajax POST request from javascript function: function UpdateMetrics() { $.ajax({ type: POST,
I am trying to use the jQuery $.post method to submit an ajax request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.