I believe it's impossible to use a relative url in requests, but you can get around this by creating a function which prepends the relevant domain to your url. (Make sure to import your settings file!)
from django.conf import settings
development_url = "http://localhost:8000/"
production_url = "http://myapisite.com/"
def create_url(relative_url):
# If you are on your development server. This is assuming your development always has DEBUG = True, and your production is always DEBUG = False
if settings.DEBUG:
return development_url + relative_url
# Production
return production_url + relative_url
Therefore print(create_url("api/test/anothertest"))
will return http://localhost:8000/api/test/anothertest
.
And this is how you would use it:
url = create_url("api/orders/shipment/")
data = requests.post(url=url, data=content, headers = headers)