我正在尝试将模板信息添加到我的视图文件中,并且我一直收到错误,表明输出错误。我这样做了吗?
from django.http import HttpResponse
from django.template import Context
from django.template.loader import get_template
def main_page(request):
template = get_template('main_page.html')
variables = Context({
'head_title': u'Django Bookmarks',
'page_title': u'Welcome to Django Bookmarks',
'page_body': u'Where you can store and share bookmarks'
})
output = template.render(variables)
return HttpResponse(output)
我一直收到缩进错误,我不知道发生了什么。提前感谢您提供任何帮助
答案 0 :(得分:1)
回溯应告诉您缩进的哪一行。
在上面粘贴的代码中,最后两行输入错误。它们应与variables = ...
一致。