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

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.

主站蜘蛛池模板: 临泉县| 库车县| 唐河县| 宜州市| 汶川县| 仙游县| 平遥县| 芒康县| 寿宁县| 景泰县| 滕州市| 新民市| 汾西县| 宜章县| 合江县| 汾西县| 双柏县| 乌拉特后旗| 桐乡市| 河西区| 宜春市| 衡水市| 梅河口市| 阳东县| 阜城县| 台中市| 九江县| 怀宁县| 应城市| 阿克陶县| 新宾| 达州市| 横山县| 吉木萨尔县| 虹口区| 长丰县| 平阳县| 浑源县| 墨脱县| 临潭县| 塔城市|