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

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.

主站蜘蛛池模板: 安西县| 衢州市| 滦南县| 新和县| 江津市| 新源县| 南康市| 宁海县| 鄂伦春自治旗| 陕西省| 新疆| 阳曲县| 乌恰县| 贵溪市| 昭苏县| 阳西县| 通海县| 平塘县| 简阳市| 长治市| 遂溪县| 镶黄旗| 正阳县| 尖扎县| 建湖县| 习水县| 青神县| 平湖市| 耒阳市| 广河县| 隆德县| 西城区| 祁门县| 吴川市| 天峨县| 云安县| 商南县| 科尔| 北宁市| 诏安县| 南陵县|