How to extract data from json response made by an api in python, Django

I am creating a charge and I want from it to take its 'hosted_url' in order to redirect a user from page.

I am trying to extract it from json, but I newbie and don't know how

        url = ""

        payload = {
            "local_price": {
                "amount": 1,
                "currency": USDT
            "name": "Test for fun",
            "description": "Project 2",
            "pricing_type": "fixed_price"
        headers = {
            "accept": "application/json",
            "X-CC-Version": "2018-03-22",
            "X-CC-Api-Key" : "**********",
            "content-type": "application/json"

        response =, json=payload, headers=headers)


This is a code to make a request to an api in order to create a charge and in JSON Response I get field:

"hosted_url": "",

I want somehow to put this message '123DVAS' in variable or to make a redirect like this:

return render(request, '')

You can do like this,

# Suppose it's your response looks like this
response = {"hosted_url": ""}
id_fecthed = response.get('hosted_url').split('/')[-1]

# You can redner like this
render(request, f'{id_fecthed}')

# If you sure that always you want to redirect to hosted_url
# Then you can use this
render(request, response.get('hosted_url'))
Back to Top