Response.json() fields start with underscore

Hi,

I am reading data from an API… and in the json it returns, some fields start with an underscore.

    "_links": {
        "next": "/wiki/api/v2/spaces?cursor=eyJpZCI6NTIxOTk0MjcsInNwYWNlU29ydE9yZGVyIjp7ImZpZWxkIjoiSUQiLCJkaXJlY3Rpb24iOiJBU0NFTkRJTkcifSwic3BhY2VTb3J0T3JkZXJWYWx1ZSI6NTIxOTk0Mjd9",
        "base": "https://elkvalleyresources.atlassian.net/wiki"
    }

Here is how I defined my function in the views.py file

    resp = requests.request("Get",uri, headers=headers, auth=userauth)
    
    response = resp.json()
    return render(request, 'spaces.html', {'response':response})

Here is how I display in the template.

        {% for i in response.results  %}
        <tr>
            <td>{{i.name}}</td>
            <td>{{i.type}}</td>
            <td>{{i.status}}</td>
            <td>{{i.createdAt}}</td>
            <td>{{i.id}}</td>
            <td>{{i.key}}</td>
            
            <td><a href="https://elkvalleyresources.atlassian.net/wiki">{{i.name}}</a>  </td>
        </tr>
        {% endfor %}

but response._links.next fails with error: Variables and attributes may not begin with underscores: ‘response._links.next’

Also tried response['_links']['next'], also fails.

any help would be greatly appreciated.

thanks.
NG.

Googling for “Variables and attributes may not begin with underscores” gives a few results. Maybe one of those works for you?

Otherwise, please provide more information. The line response._links.next is not in the code you showed. Please give a complete example we can easily run on our machines without having to add any code.

Also, next time please mention that the error message is being produced by django, not by requests. Response.json() is not actually the function that fails. Also, please show complete tracebacks from error messages, they often contain useful information to make it easier for us to help you.

Thanks…

I will follow your advice… and google it…
Also will follow your indication next time.