我开发了一个django项目。
我想在html上显示输出字符串。
我的观点是:
def strategy_run(request):
output = "hello world!\nstring test"
return render_to_response('strategy_run.html', locals())
我的strategy_run.html是:
<!DOCTYPE html>
<html lang="en">
<body>
{{output}}
</body>
</html>
但我希望html如下所示:
hello world!
string test
它们的html可能是"hello world!<br>string test"
。
那么如何将字符串转换为html格式呢?
有没有python或django函数来改变格式?
谢谢。
发布于 2017-02-16 18:03:17
我不完全确定你在问什么,但听起来你可能想要linebreaks
或linebreaksbr
template filters。
发布于 2017-02-16 18:05:55
有多种方式可以做到这一点。
from django.http import HttpResponse
def strategy_run(request):
return HttpResponse("hello world!<br>string test")
第二位
def strategy_run(request):
output = "hello world!<br>string test"
return render_to_response('strategy_run.html', locals())
仅在您的stragegy_run.html中排名第三
<!DOCTYPE html>
<html lang="en">
<body>
{{ output|linebreaksbr }}
</body>
</html>
https://stackoverflow.com/questions/42270605
复制相似问题