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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:30:13+00:00 2026-06-07T20:30:13+00:00

I am trying to send an HTTPS PUT request to a RESTful API Django

  • 0

I am trying to send an HTTPS PUT request to a RESTful API Django web service using a djangorestframework (DRF: http://django-rest-framework.org/) View. I cannot get this to work due to Django’s Cross Site Request Forgery (CSRF) protection.

The PUT request is intended to allow unauthenticated users to add a resource.

What I have considered/tried:

  1. Disabling CSRF — not acceptable. The API runs on the same Django instance as the non-API service. Disabling CSRF protection is too much risk.
  2. Using the X-Requested-With: XMLHttpRequest header on the PUT request (I control the clients). Doesn’t work — I still get the CSRF error.
  3. Using the @crsf_exempt decorator on the PUT view. I would if I could — the framework defines a class, not a view.

My current best option is to write PUT views myself without using DRF’s View class. I can then use the @crsf_exempt decorator successfully.

I’d like to use DRF’s View class — but cannot see how. Can you?

  • 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-07T20:30:14+00:00Added an answer on June 7, 2026 at 8:30 pm

    Thanks to James Cran Wellward, I was also able to solve this issue by using the method_decorator.

    class ExampleView(ResponseMixin,View):
      renderers=DEFAULT_RENDERERS
      def get(self,request):
        response=Response(200,{'msg':'called via GET'})
        return self.render(response)
      def post(self,request):
        response=Response(200,{'msg':'called via POST'})
        return self.render(response)
      @method_decorator(csrf_exempt):
      def dispatch(self,*args,**kwargs):
        return super(EampleView,self).dispatch(*args,**kwargs)
    

    and then test it:

    curl -X GET http://www.example.com/rest/exampleview/
    

    returns:

    {msg: 'called via GET'}
    

    and

    curl -X POST http://www.example.com/rest/exampleview/
    

    returns:

    {msg: 'called via POST'}
    

    HTH. see the original post.

    • 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 to Parse: https://parse.com/docs/rest#objects-creating . Can't get it
I am using https://github.com/plataformatec/simple_form and am trying to send a extra parameter. I have
Trying to find a way to send a POST HTTPS request from Python to
I'm trying to send a http get request in a php file to a
I am trying to send a generic list to a jersey servlet using put
I am trying to query an api through JSON / REST using Ruby. require
I'm trying to send a HTTP request to a servers interface. But I'm really
I'm trying to send an http get request via the httplib, but I'm facing
I am trying to send a PUT request to a particular URL, and have
I am trying to send data to DotNetOpenAuth website as described here http://msdn.microsoft.com/en-us/library/debx8sh9.aspx Sender

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.