I'm looking for developping Django REST API
from my web application and I would like to try creating object through the API. Mainly if my process is well-implemented.
I'm using a python file in order to make that.
This is my file :
import requests
url = 'http://localhost:8000/Api/identification/create/'
data = {
"Etat": "Vivant",
"Civilite": "Monsieur",
"Nom": "creation",
"Prenom": "via-api",
"Sexe": "Masculin",
"Statut": "Célibataire",
"DateNaissance": "1991-11-23",
"VilleNaissance": "STRASBOURG",
"PaysNaissance": "FR",
"Nationalite1": "FRANCAISE",
"Nationalite2": "",
"Profession": "Journaliste",
"Adresse": "12, rue des fleurs",
"Ville": "STRASBOURG",
"Zip": 67000,
"Pays": "FR",
"Mail": "",
"Telephone": "",
"Image": "http://localhost:8000/media/pictures/HH_Hh_19212-00001-979812-2_ShUDIk8.jpg",
"CarteIdentite": "http://localhost:8000/media/Carte_Identite/carte_ID_lzpOI41_WOnC9WH.gif"
}
response = requests.post(url, data=data)
print (response.text)
I'm confusing if I have to use post
or put
, but anyway, I don't overcome to create my object. If I make the process directly through the API, it works, but not with a pythonic file.
Any idea ?
EDIT :
For example, it works with these files :
#API_list.py
import requests
url = 'http://localhost:8000/Api/Identification/'
response = requests.get(url)
print (response.text)
and
#API_details.py
import requests
url = 'http://localhost:8000/Api/Identification/26/'
response = requests.get(url)
print (response.text)
and
#API_edit.py
import requests
url = 'http://localhost:8000/api/Identity/26/edit/'
data = {
"Ville": "STRASBOURG",
"Zip": 67000,
"Pays": "FR",
"Adresse": "12, rue de la mésange",
"Telephone": "0388603938",
"Mail": "ceciestuntest@datasystems.fr",
}
response = requests.put(url, data=data)
print (response.text)