简体   繁体   中英

How can i make the text in my web server change line

Hey i did a small project to display text on a web server but for some reason all the text is on the same line and i don't know how to change it.

code:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def main():
    return """fxfxzvxczxcvxvzx
cxzvxczxcvcxvfdsvxz"""

if __name__ == "__main__":
    app.run(debug=True, host="127.0.0.1", port=5050) 

In your case you need to pass your output as html format to frontend; <br> and </br> are linebreaker tags in html;

Try this:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def main():
    template = "fxfxzvxczxcvxvzx</br>cxzvxczxcvcxvfdsvxz"
    return template

if __name__ == "__main__":
    app.run(debug=True, host="127.0.0.1", port=5050)

Notes:

if you want to setup and export html format on larger scale you need to do it by flask template engine render or designer-friendly templating language like jinja just check these three links:

  1. https://flask.palletsprojects.com/en/1.1.x/quickstart/#rendering-templates
  2. https://flask.palletsprojects.com/en/1.1.x/tutorial/templates/
  3. https://jinja.palletsprojects.com/en/2.11.x/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM