flask- Basic Operation

#flask

Operation ###
1. Import frame
2. Examples of object
3. Decorative route navigation url address
4. view routing function processing when the browser is opened decorative route, view corresponding function is executed,
there must be a return value: String, or .html template file
template .html templates must be placed in a folder


### Home navigation bar
http://127.0.0.1:5000/

from flask import Flask,url_for,request #from flask import *
app = Flask(__name__)

app.route @ ( '/')
DEF index ():
return 'home'

if __name__ == '__main__':
app.run(debug=True)

 


### ordinary navigation bar
http://127.0.0.1:5000/log

@app.route('/log')
def log():
return 'log'

url_for('log') #http://127.0.0.1:5000/log

 

### pass parameters navigation bar
http://127.0.0.1:5000/log/chen/14

@app.route('/log/<name>/<int:age>')
def log(name,age):
return 'log'


url_for('log',name='chen',age=14) #http://127.0.0.1:5000/log/chen/14

 

Guess you like

Origin www.cnblogs.com/chenlulu1122/p/11888871.html