Python Flask Get Started
Flask
Flask is simple WebFramework for Python.
Different from Django, the feature is simple. But it becomes more and more popular.
Install
If you have pip, just simple
pip3 install Flask
First Simple Application
To create project, Flask doesn’t have any command.
Create project folder by myself and make python file
main.py
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__== '__main__': app.run()
Create simple routing and application run code.
To start this web application run python
python3 main.py
This application runs with http://localhost:5000
Debug Mode
Debug mode is helper for debug application.
To add one line, we can test without stop and run.
This plays auto reload
app = Flask(__name__) app.debug = True # Debug mode on