- 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.
推薦閱讀
- UI設計基礎培訓教程
- Google Flutter Mobile Development Quick Start Guide
- Learning Flask Framework
- Unity 2020 Mobile Game Development
- C語言程序設計教程(第2版)
- HTML5從入門到精通 (第2版)
- 執劍而舞:用代碼創作藝術
- Visual Foxpro 9.0數據庫程序設計教程
- 愛上micro:bit
- Android移動應用開發項目教程
- Java EE架構設計與開發實踐
- 企業級Java現代化:寫給開發者的云原生簡明指南
- Web程序設計與架構
- 深入理解Zabbix監控系統
- Instant SQL Server Analysis Services 2012 Cube Security