我有为 xml 生成数据的函数,我想使用一个模板:
<?xml version="1.0" encoding="utf-8"?>
<items>
{% for item in items %}
<item>
<title>{{ item.title }}</title>
<desc>{{ item.desc }}</desc>
</item>
{% endfor %}
</items>
但如果我使用:
t = loader.get_template(templatename)
c = RequestContext(request, generated_data)
return HttpResponse(t.render(c))
我得到结果:
<html>
<head></head>
<body>
<?xml version="1.0" encoding="utf-8"?>
<items>
<item>
<title>Title 1</title>
<desc>desc 1</desc>
</item>
<item>
<title>Title 2</title>
<desc>desc 2</desc>
</item>
<item>
<title>Title 3</title>
<desc>desc 3</desc>
</item>
</items>
</body>
</html>
如何防止这个标题?