python3-flask-1 write the first page

  • installation
python3 -m pip install flask
  • Write a python script

vim flask.py

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
 
from flask import Flask
 
app = Flask(__name__)
 
@app.route('/')
def index():
    return 'Hello Flask!'
 
if __name__ == '__main__':
    app.run('127.0.0.1', '5000')

'from flask import Flask' call flask of Flask module
'App = Flask ( name )' Flask class has only one must specify the parameters, i.e., the main program module or a package name, __ name__ is a system variable, which means that the present py file name
"@ app.route ( '/') " routing functions and views
"def index ()" access path corresponding to the module
"return 'Hello Flask!'" return result
"app.run ( '127.0.0.1 ',' 5000 ') "start flask and listening on port

Guess you like

Origin www.cnblogs.com/taoyuxuan/p/11842579.html