user3236034
user3236034

Reputation: 463

How to request PUT, POST methods on Django rest framework

I've been working with django restframework, I have not managed to make a PUT or a POST to JSON, I could only make a post with the form of the rest django web interface framework As I can make a PUT, POST to be called from an app

Upvotes: 0

Views: 2197

Answers (1)

Bibhas Debnath
Bibhas Debnath

Reputation: 14939

It's not about Django. All the other HTTP methods except GET, e.g. PUT, POST, DELETE etc require a form to simulate. Because when the HTTP request is made, the request needs to mention what type of request it is. When you enter an URL on the browser address bar, it's always GET. You can write a form and modify it's method attribute to say if it's PUT, POST etc. Other ways to request those methods is to use a http library like requests or simple Javascript

var xmlhttp;

function test(){
    execute('GET', 'http://server.com/testServer.php');
    execute('POST', 'http://server.com/testServer.php');
    execute('PUT', 'http://server.com/testServer.php');
    execute('DELETE', 'http://server.com/testServer.php');
}

function execute($method,$url){
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open($method,$url,true)
    xmlhttp.send(null);
}

You can read this question for more details. JS snippet taken from here.

Upvotes: 1

Related Questions