Home > Blockchain >  Django: How to make json data readable in django?
Django: How to make json data readable in django?

Time:05-13

i am trying to retrieve the lastest news from hackernews api, everthing seems to be working fine and when i print the status code, i get Status Code:200. Now i am getting some data but they are not readable this is how there are displayed

b'[31349988,31344981,31348529,31344863,31341698,31348097,31347740,31348772,31347286,31348463,31345478,31348316,31345749,31347983,3'

and this is code i used to retrieve the data from the api enter image description here

index.html

{% story in response %}
   {{ story.title }}
{% endfor %}

CodePudding user response:

Your requests.get() returns an object. So, to make it readable, simply pass .json() method, like so:

def index(request):
    response = requests.get("https://hacker-news.firebaseio.com/v0/topstories.json").json()
    return render(request, "index.html", {'response': response})

CodePudding user response:

enter image description here

That API gives an array integer as a response. So I supposed API manipulation error. So plz inform the API creator and get advice from them.

  • Related