Flask – Application
So as to test Flask installation, type the following code in the manager as Hello.py
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World’ if __name__ == '__main__': app.run()
Importing cup module in the task is obligatory. An object of Flask class is our WSGI application.
Flask constructor takes the name of current module (__name__) as argument.The route() capacity of the Flask class is a decorator, which tells the application which URL should call the associated function.
The rule parameter binding to URL official with the function.
The options is a list of parameters to be sent to the underlying Rule object.
Finally the run() method of Flask class runs the application on the local development server.
app.run(host, port, debug, options)
All parameters are optional
|Sr.No.||Parameters & Description|
Hostname to listen on. Defaults to 127.0.0.1 (localhost). Set to ‘0.0.0.0’ to have server available externally
Defaults to 5000
Defaults to false. If set to true, provides a debug information
To be forwarded to underlying Werkzeug server.
Debug modeA Flask application is begun by calling the run() technique. In any case, while the application is a work in progress, it ought to be restarted physically for each adjustment in the code. To keep away from this bother, empower debug support. The server will at that point reload itself if the code changes. It will likewise give a valuable debugger to follow the mistakes assuming any, in the application.
The Debug mode is enabled by setting the debug property of the application object to True before running or passing the investigate parameter to the run() method.
app.debug = True app.run() app.run(debug = True)