通过烧瓶渲染模板传递到html文件的文本格式不正确

时间:2020-07-27 06:26:36

标签: python html css machine-learning flask

我正在尝试通过烧瓶将歌词传递给html文件,但格式不正确。

这就是我想要的格式,我将它以相同的格式传递给text变量- The value of the text variable

这是它在html网站中的显示方式-The actual result

由于它已经以格式化的方式传递,因此如何在网站上正确格式化它。

这是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>

1 个答案:

答案 0 :(得分:1)

我得到了答案,只需要使用空白:pre-line即可使行溢出

.result {
margin: center
width: 100%;
white-space: pre-line;
border: 1px solid #ccc;
}

The Final Result

相关问题