一:创建一个Web Project
在“新建项目”对话框中,选择Installed下面的Python下的Web,在中间的列表中选择“Web Project”,给项目一个“HelloWebPython”这样的名称,然后点击OK。
点击OK之后
安装Flask库,步骤如下:
a.在在Solution Explorer 下,右击Python 3.6(64-bit) (global default) ;选择 Install Python Package…
b.搜索Flask库,运行指令,并下载Flask库,如下图:
c.点击之后,看Output窗口
d.检查是否在Python 3.6(64-bit) (global default) 下面,方法是:左击Python 3.6(64-bit) (global default)看是否有Flask,若有则安装成功,否则重新安装Flask库
from flask import Flask
# Create an instance of the Flask class that is the WSGI application.
# The first argument is the name of the application module or package,
# typically __name__ when using a single module.
app = Flask(__name__)
# Flask route decorators map / and /hello to the hello function.
# To add other resources, create functions that generate the page contents
# and add decorators to define the appropriate resource locators for them.
@app.route('/')
@app.route('/hello')
def hello():
# Render the page
return "HelloWeb Python!"
if __name__ == '__main__':
# Run the app server on localhost:4449
app.run('localhost', 4449)