官术网_书友最值得收藏!

  • Flask By Example
  • Gareth Dwyer
  • 123字
  • 2021-07-09 20:06:54

Creating a new Flask application

To begin with, we'll create the skeleton of our new Flask application, which is pretty much the same as our Hello World application. Open headlines.py in your editor and write the following code:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def get_news():
  return "no news is good news"

if __name__ == '__main__':
  app.run(port=5000, debug=True)

This works exactly as before. You can run it in your terminal with python headlines.py. Open a browser and navigate to localhost:5000 to see the no news is good news string displayed. However, although the old adage may be true, it's bad news that our app does not do anything more useful than this. Let's make it display actual news to our users.

主站蜘蛛池模板: 永城市| 兰坪| 高尔夫| 太仓市| 桐城市| 缙云县| 高平市| 凌云县| 上虞市| 南投县| 资溪县| 凌云县| 隆尧县| 奉节县| 民勤县| 双桥区| 遂平县| 项城市| 华蓥市| 安达市| 溧水县| 南京市| 寻甸| 星子县| 舒兰市| 会东县| 道真| 若羌县| 容城县| 抚宁县| 明星| 山丹县| 壤塘县| 沭阳县| 高密市| 孟津县| 保定市| 合山市| 隆昌县| 长汀县| 博罗县|