Flask is a lightweight web application framework written in Python.
Here are some basic commands and notes for Flask:
1.Install Flask:
pip install Flask
2.Import Flask in your Python file:
from flask import Flask
3.Create a Flask app instance:
app = Flask(__name__)
4.Define a route using the @app.route() decorator:
@app.route('/')
def home():
return 'Hello, World!'
5.Run the Flask app:
if __name__ == '__main__':
app.run()
6.Access the app in your browser at
http://localhost:5000/
7.To pass variables in a URL, use angle brackets in the route definition:
@app.route('/user/<name>')
def user(name):
return f'Hello, {name}!'
8.To run the app in debug mode, set the debug parameter to True:
if __name__ == '__main__':
app.run(debug=True)
These are just the basics of Flask. There are many more features and commands available in the framework.
There is a free Udemy course available for beginners on Python Flask at the following link:
https://www.udemy.com/course/python-flask-for-beginners/
Top comments (0)