This is the continuation of my question yesterday and I'm now trying to show the fetched data on the django template.
Can anyone help me?
I'm trying to show the fetched data on an API to the Django template.
Here's what I've tried on
home.html
<h1>Title: {{data.title}}</h1>
Here's my views.py
which gets the data from services.py
class IndexData(TemplateView):
def get(self, request):
article_data = services.get_data()
return render(request, 'pages/home.html', article_data)
Here's the services.py
def get_data(title, url, description,
…
Top comments (7)
Hello Vicente,
It appears that the
data
passed to the template is a list, so you would need a loop to access thetitle
for each item.HA! Thank you!
You're right, I forgot to loop through the data.
No problem, glad to help.
I don't have a SO account though to answer the question there.
Do you want to answer the question on SO?
Hello,
You can use the requests Library to make it .
First of all, you need to serialize the data and send them to your template.
It's late night, tomorrow i will share with you a live example.
Thanks
SOLVED
Yep. Turns out I forgot to loop through the data on the template. But I'l still study DRF to learn how to serialize data. Thanks.