这就是我在Flask app.py中的内容。
look
这就是我在html页面标签中的内容。问题是Javascript将“\ n”视为实际的新行。有没有办法对它进行编码,这样就不必在app.py
中加倍反斜杠data = "date,New York,San Francisco,Austin\n20111001,63.4,62.7,72.2\n20111002,58,59.9,67.7\n" \
"20111003,53.3,59.1,69.4\n20111004,55.7,58.8,68\n20111005,64.2,58.7,72.4\n20111006,58.8,57,77\n" \
"20111007,57.9,56.7,82.3\n20111008,61.8,56.8,78.9\n20111009,69.3,56.7,68.8\n20111010,71.2,60.1,68.7\n"
return render_template("chart.html", title="NY, SF, Austin Comparision", data=data)
答案 0 :(得分:0)
实际上你可以使用替换过滤器
var data = "{{ data|replace("\n","\\n") }}";