[10] tutorial Flask Flask-Script extension

Flask-Script extension

By using Flask-Script extension, we can start the server when Flask, by way of command line parameters passed. Not just by app.run () method of mass participation, for example, we can:

python hello.py runserver -host ip address

 

This code tells the server which network interface to listen for connections from clients. By default, the server listens only from the computer where the server initiated connection, that localhost connections.

We can see the parameters python hello.py runserver --help.

Code

  • Flask-Script mounting extension
pip install flask-script
  • Integrated Flask-Script
from Flask Import the Flask
 from flask_script Import Manager 

App = the Flask ( the __name__ )
 # associate the application instance and class Manager 
Manager = Manager (App) 

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

IF  the __name__ == " __main__ " : 
    manager.run ()

 

Flask-Script can also add the current application script command, subsequent projects will be used to

Guess you like

Origin www.cnblogs.com/zeug/p/11367427.html
Recommended