Django模板 - 没有变量

时间:2012-12-24 22:23:12

标签: 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')
    return HttpResponse(html)

testing.html

<html>


<body>


THIS IS A TEST PAGE. 


</body>

</html>

在我的本地服务器页面上,我看到的只有:这是'&gt;

我没有看到其余的。你能告诉我有什么问题吗?非常感谢。

1 个答案:

答案 0 :(得分:1)

您需要渲染模板。将最后一行更改为:

return HttpResponse(html.render(Context()))

您还需要从django.template导入Context。您可能还需要考虑使用render_to_response快捷方式。这些内容包含在part 3 of the tutorial中。

相关问题