![](/img/trans.png)
[英]Need update value passed by render_template with flask in html template td tag every 10 seconds
[英]The Text passed through the flask render template to the html file is not formatting properly
我正在尝试通过 flask 将歌词传递给 html 文件,但格式不正确。
这就是我希望它的格式,并且我以相同的格式将它传递到文本变量中 -文本变量的值
这就是它在 html 网站上的显示方式 -实际结果
我如何在网站上正确格式化它,因为它已经以格式化的方式传递。
这是 python 代码 -
import flask
import subprocess
import sys
import generate_unconditional_samples as model
app = flask.Flask(__name__, template_folder='templates')
@app.route('/', methods=['GET', 'POST'])
def main():
if flask.request.method == 'GET':
return(flask.render_template('main.html'))
if flask.request.method == 'POST':
text = model.sample_model("Lyric", None, 0, 1, None, 0.8, 40, 0.0)
print(text)
return flask.render_template('main.html', result = text,)
if __name__ == '__main__':
app.run()
这是 HTML 代码 -
<!doctype html>
<html>
<style>
form {
margin: auto;
width: 35%;
}
.result {
margin: auto;
width: 100%;
border: 1px solid #ccc;
}
</style>
<head>
<title>Lyric Generator</title>
</head>
<body>
<form action="{{ url_for('main') }}" method="POST">
<fieldset>
<input type="submit">
</fieldset>
</form>
<div class="result" align="center">
{% if result %}
<br> Generated Lyrics:
<p style="font-size:20px">{{ result }}</p>
{% endif %}
</div>
<body>
</html>
我得到了答案,只需要使用 white-space: pre-line 来溢出线条
.result {
margin: center
width: 100%;
white-space: pre-line;
border: 1px solid #ccc;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.