2017-02-16 12 views
0

私はdjangoプロジェクトを開発します。文字列をHTML形式に変更するにはどうすればよいですか?

出力文字列をhtmlに表示します。

私の見解は以下のとおりです。

<!DOCTYPE html> 
<html lang="en"> 
<body> 
{{output}} 
</body> 
</html> 

しかし、私は、HTMLのような表示したい:

def strategy_run(request): 
    output = "hello world!\nstring test" 
    return render_to_response('strategy_run.html', locals()) 

私strategy_run.htmlがある

hello world! 
string test 

彼らのHTMLは"hello world!<br>string test"かもしれません。

だから、文字列をHTML形式に変更するにはどうすればよいですか?

フォーマットを変更するためのpythonまたはdjango関数はありますか?

ありがとうございます。

+0

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()) 

第三 – e4c5

答えて

2

あなたが求めていることは完全にはわかりませんが、あなたが望むように聞こえるかもしれません。linebreaksまたはlinebreaksbrtemplate filters

2

これを行うには複数の方法があります。あなたは\ nを入れ
をプッによってあなたのstragegy_run.htmlのみ

<!DOCTYPE html> 
<html lang="en"> 
<body> 
{{ output|linebreaksbr }} 
</body> 
</html> 
関連する問題