I am watching a django tutorial (Corey Schafer on how to build a webapp, however I had to use a different method of getting the template to appear. That is all working well. The function he uses has an argument where I don’t, that allows the dictionary to appear on the site. Any ideas on how to fix this? (sorry if this is a rookie question, I’m very new)
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
def home(request):
context = {
'news': news
}
template = loader.get_template('home.html')
return HttpResponse(template.render())
I tried to pass it through alongside template.render() and it made all of the raw HTML code come up on screen.
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.