* Serving Flask app 'app'
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 123-456-789
步骤 4:访问服务器
打开浏览器,输入以下地址:
http://127.0.0.1:5000/
你应该会看到页面显示:
Hello, World!
步骤 5:扩展功能(可选)
现在你已经有了一个基本的网络服务器,可以进一步扩展功能。例如:
1、添加更多路由
可以在 `app.py` 中添加更多的路由和视图函数:
python
@app.route('/about')
def about():
return This is an about page.
@app.route('/contact')
def contact():
return Contact us at info@65.hk
3、使用模板渲染页面
Flask 支持使用 Jinja2 模板引擎来渲染 HTML 页面。首先,在项目目录中创建一个 `templates` 文件夹,并在其中创建一个 `index.html` 文件:
html
<! templates/index.html
<!DOCTYPE html
<html
<head
<titleHome Page</title
</head
<body
<h1Welcome to the Home Page!</h1
</body
</html
然后修改 `app.py`:
python
from flask import render_template