refactor major
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import requests
|
||||
from urllib.parse import urljoin
|
||||
from datetime import date, datetime
|
||||
import json
|
||||
class django_crud_api():
|
||||
def __init__(self,**kwargs):
|
||||
@@ -58,8 +59,11 @@ class django_crud_api():
|
||||
try:
|
||||
files=d.pop("files",None)
|
||||
headers = None #{'Content-type': 'application/json'}
|
||||
print("Create %s" % d["slug"])
|
||||
#print("Create %s" % d["slug"])
|
||||
# print("Create with data %s" % str(d))
|
||||
#for k in d:
|
||||
# if type(d[k]) is date:
|
||||
# d[k]=str(d[k])
|
||||
r = requests.post(self.endpoint,headers=headers,data=d,files=files)
|
||||
r.raise_for_status()
|
||||
except requests.exceptions.RequestException as e:
|
||||
@@ -69,8 +73,8 @@ class django_crud_api():
|
||||
print("Tryed to reach %s with POST Action" % self.endpoint)
|
||||
|
||||
|
||||
return None
|
||||
if r.status_code==200:
|
||||
return r.json()
|
||||
print(r)
|
||||
return r
|
||||
return r.status_code, None
|
||||
if r.status_code==201:
|
||||
return r.status_code, r.json()
|
||||
#print(r)
|
||||
return r.status_code, r
|
||||
|
||||
Reference in New Issue
Block a user