flask open debug four models

flask open debug four models


 

 

  • In app.run added a parameter (), 'debug = True' can turn on debug mode
    from flask import Flask
    
    app = Flask(__name__)
    
    
    
    @app.route('/')
    def hello_world():
        return 'Hello World!'
    
    
    if __name__ == '__main__':
        app.run(debug=True)
  • The debug attribute assignment app is True
     1 from flask import Flask
     2 
     3 app = Flask(__name__)
     4 app.debug = True
     5 
     6 
     7 @app.route('/')
     8 def hello_world():
     9     return 'Hello World!'
    10 
    11 
    12 if __name__ == '__main__':
    13     app.run()
  • Debug mode is provided in the form of configuration parameters: 'app.config.update (DEBUG = True)'
     1 from flask import Flask
     2 
     3 app = Flask(__name__)
     4 app.config.update(DEBUG=True)
     5 
     6 
     7 @app.route('/')
     8 def hello_world():
     9     return 'Hello World!'
    10 
    11 
    12 if __name__ == '__main__':
    13     app.run()
  • DEBUG mode setting configuration file in the form of 'app.config.from_object (config)'
    • New config file
      • Write to
        • DEBUG = True
    •  1 from flask import Flask
       2 import config
       3 app = Flask(__name__)
       4 app.config.from_object(config)
       5 
       6 
       7 @app.route('/')
       8 def hello_world():
       9     return 'Hello World!'
      10 
      11 
      12 if __name__ == '__main__':
      13     app.run()

       from_object can be replaced from_pyfile from_pyfile pass a filename string

 

Flask 1.0 versions prior to FLASK_ENV environment variable is no longer supported

Open two ways to debug:

  1:  Click pycharm the run, select edit configuration, check FlASK_DEBUG, then take a debug mode can be turned on

  2: Command line:

        export FLASK_ENV=development # Windows将export 换成 set

        flask run

 

 

Guess you like

Origin www.cnblogs.com/ivy-blogs/p/11470302.html