Django模板--无变量
如果这是一个愚蠢的问题,我很抱歉。我已经试着找到一个解决方案好几个小时了,我是新手,不是很聪明 我的网页没有显示全文。它只显示很少的文本 views.py:Django模板--无变量,django,templates,django-templates,Django,Templates,Django Templates,如果这是一个愚蠢的问题,我很抱歉。我已经试着找到一个解决方案好几个小时了,我是新手,不是很聪明 我的网页没有显示全文。它只显示很少的文本 views.py: Create your views here. from django.template import loader from django.http import HttpResponse def testing(request): html = loader.get_template('testing.html')
Create your views here.
from django.template import loader
from django.http import HttpResponse
def testing(request):
html = loader.get_template('testing.html')
return HttpResponse(html)
testing.html
<html>
<body>
THIS IS A TEST PAGE.
</body>
</html>
这是一个测试页面。
在我的本地服务器页面上,我看到的是:这是'>
剩下的我看不到了。你能告诉我怎么了吗?非常感谢你 您需要渲染模板。将最后一行更改为类似以下内容:
return HttpResponse(html.render(Context()))
您还需要从django.template导入上下文。您可能还需要考虑使用ReleDytoTyAcRead快捷方式。这些内容已包含在中。您确定它正在拾取您认为是的模板吗?嗨,Ignacio,谢谢您的回复。是的,我肯定。我改变了它,它只显示了前几个字。再次感谢你,谢谢你,维尼!那真的很好用!我不知道如果没有变量,就需要上下文。谢谢你的澄清,你真的帮了我很多忙!再次感谢!