- 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.
推薦閱讀
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- Mastering Selenium WebDriver
- Python Deep Learning
- Animate CC二維動(dòng)畫設(shè)計(jì)與制作(微課版)
- Java虛擬機(jī)字節(jié)碼:從入門到實(shí)戰(zhàn)
- 精通Scrapy網(wǎng)絡(luò)爬蟲
- MySQL數(shù)據(jù)庫(kù)管理與開發(fā)實(shí)踐教程 (清華電腦學(xué)堂)
- ADI DSP應(yīng)用技術(shù)集錦
- Hands-On Enterprise Automation with Python.
- Python深度學(xué)習(xí):模型、方法與實(shí)現(xiàn)
- 一塊面包板玩轉(zhuǎn)Arduino編程
- Practical GIS
- Python程序設(shè)計(jì)現(xiàn)代方法
- 走近SDN/NFV
- JSP編程教程