0

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

Bibhas Debnath
  • 13,319
  • 14
  • 64
  • 93
user3236034
  • 443
  • 2
  • 5
  • 14
  • What's your problem? Where is your code? What error message did you face? – Bibhas Debnath Mar 15 '14 at 19:24
  • Hi, I'm a newbie with django, my problem is I'm working with Django REST Framework, I get the data well with JSON (... /? format = json) format I use the GET url in an application for android, but I failed to know how to make a PUT, POST from restframework django without using the form that has the default page, is there any way to make a POST using the url of the page, as when I do a GET? for then I could run it from android. but I could not know how to do this I have searched but I am not clear – user3236034 Mar 16 '14 at 02:52

1 Answers1

1

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.

Community
  • 1
  • 1
Bibhas Debnath
  • 13,319
  • 14
  • 64
  • 93