0

如果这是一个愚蠢的问题,我很抱歉。我试图找到一个解决方案几个小时,我是新手,不是很聪明。

我的网页没有显示全文。它只显示很少的文字。

视图.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)

测试.html

<html>


<body>


THIS IS A TEST PAGE. 


</body>

</html>

在我的本地服务器页面上,我看到的只是:这是'>

我看不到其余的。你能告诉我有什么问题吗?太感谢了。

4

1 回答 1

1

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

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

您还需要从 django.template 导入 Context。您可能还想考虑使用 render_to_response 快捷方式。本教程的第 3 部分介绍了这些内容。

于 2012-12-25T00:17:45.827 回答