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 8187057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:26:08+00:00 2026-06-07T02:26:08+00:00

I’m trying to create a web service in Django. For some reason it is

  • 0

I’m trying to create a web service in Django. For some reason it is working in a GET request but not as a POST (which is my requirement). I have the below url:

url(r'^rest/user/(.*)/(.*)/$', 'rest.views.user.user')

So if the user was to send a message to /rest/user/ANY_CHARACTER/ANY_CHARACTER/, it will go to the below function:

def user(request, string1, string2):
    if request.method == "POST":
        return HttpResponse(string1 +  ' ' + string2)
    else:
        return HttpResponse('error')

Everytime I send a GET request, i’m getting error (which is correct), but everytime I send the same URL as POST, i’m getting HTTP 500 error. Is there something i’m missing here?

EDIT

The error log in the terminal has the following:
[02/Jul/2012 19:13:57] "POST /rest/user/hi/hi HTTP/1.1" 500 61994

However, when I send the same command as GET, I’m not getting any errors…which is very strange.

EDIT 1

I’m noticing the below error when I send a POST request, it works on all other types:

<p>Reason given for failure:</p>
<pre>
CSRF token missing or incorrect.
</pre>


<p>In general, this can occur when there is a genuine Cross Site Request Forgery, or when
<a href='http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ref-contrib-csrf'>Django's
CSRF mechanism</a> has not been used correctly.  For POST forms, you need to
ensure:</p>

My question is…how do I handle this for webservice requests? Sorry, tried searching for this, but is there a way to get around CSRF for RESTful webservice requests?

  • 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-07T02:26:10+00:00Added an answer on June 7, 2026 at 2:26 am

    You can do it like this:

    from django.views.decorators.csrf import csrf_exempt, csrf_protect
    
    @csrf_exempt
    def user(request, string1, string2):
        if request.method == "POST":
            return HttpResponse(string1 +  ' ' + string2)
        else:
            return HttpResponse('error')
    

    I should add that csrf_exempt is probably not safe…but will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

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.