I’m new to Django. My views.py file looks like this –
from django.shortcuts import render
from django.http import HttpResponse
import twitterData
# Create your views here.
def home(request):
profiles = twitterData.getTwitterProfileData()
return render(request, "blog/home.html", profiles)
This code works fine, profiles is simply a dict of user profile names gathered from Twitter api. Only thing is I want to put this also {“Title”: “Home”}. This would allow the page to display the correct title.
I try and write the code like this –
# Create your views here.
def home(request):
profiles = twitterData.getTwitterProfileData()
return render(request, "blog/home.html", {profiles, "title": "Home"})
and it doesn’t run. How can I use multiple items to send to page?
2
Answers
You can create a dictionary that contains all data you want to render in your view.
access it in your template like:
{{ profiles }}
and{{ title }}
It should be like this:
or you can use context as suggested before.