Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在django模板中插入带标记的字符串_Django_Django Templates_Django Views - Fatal编程技术网

在django模板中插入带标记的字符串

在django模板中插入带标记的字符串,django,django-templates,django-views,Django,Django Templates,Django Views,我在views.py中有这样的代码 template = loader.get_template('mysite/index.html') context = Context({'try':'<h1>Header no 1</h1>'}) return HttpResponse(template.render(context)) template=loader.get_模板('mysite/index.html')) context=context({'try':'he

我在views.py中有这样的代码

template = loader.get_template('mysite/index.html')
context = Context({'try':'<h1>Header no 1</h1>'})
return HttpResponse(template.render(context))
template=loader.get_模板('mysite/index.html'))
context=context({'try':'headerno1'})
返回HttpResponse(template.render(context))
在index.html中,我编写了

<html>
<body>
   {{ try }}
</body>
</html>

{{try}
相反,标题收到了行标记和所有东西。 如何修复它?

试试这个:

from django.utils.safestring import mark_safe

template = loader.get_template('mysite/index.html')
context = Context({'try': mark_safe('<h1>Header no 1</h1>')})
return HttpResponse(template.render(context))
来自django.utils.safestring导入标记\u safe
template=loader.get_模板('mysite/index.html'))
context=context({'try':标记_safe('Header no 1'))
返回HttpResponse(template.render(context))
试试这个:

from django.utils.safestring import mark_safe

template = loader.get_template('mysite/index.html')
context = Context({'try': mark_safe('<h1>Header no 1</h1>')})
return HttpResponse(template.render(context))
来自django.utils.safestring导入标记\u safe
template=loader.get_模板('mysite/index.html'))
context=context({'try':标记_safe('Header no 1'))
返回HttpResponse(template.render(context))

您能否澄清“标题接收行标记和所有内容”的含义?输出是什么样子的?谢谢。我的意思是,不要用大号字母,输出看起来像

标题1。你能澄清一下“标题收到的行标记和所有东西”是什么意思吗?输出是什么样子的?谢谢。我的意思是,输出看起来像

头1,而不是大号字母