在django模板中插入带标记的字符串
我在views.py中有这样的代码在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
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))
您能否澄清“标题接收行标记和所有内容”的含义?输出是什么样子的?谢谢。我的意思是,不要用大号字母,输出看起来像