Flask is a micro web framework for Python that enables developers to build web applications quickly and efficiently. Unlike full-stack frameworks, Flask is minimalistic and does not include built-in tools for database management, form validation, or user authentication. Instead, it allows developers to choose external libraries or extensions to add these functionalities as needed.
Flask is designed to be simple to use, providing developers with flexibility and control over their applications. It follows a modular design, making it easy to scale applications from small projects to large, complex systems.
Flask offers several powerful features that make it a popular choice for web development:
Here is an example that demonstrates some of Flask's features:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return "Welcome to the Flask Overview!"
@app.route('/about')
def about():
return render_template('about.html', name="Flask Framework")
if __name__ == '__main__':
app.run(debug=True)
This example showcases the following features:
@app.route
decorator defines routes for the root URL (/
)
and the /about
URL.about
function uses the render_template
function
to load an HTML file (about.html
) with dynamic content.debug=True
option enables Flask's debugger for easier troubleshooting.To test this example:
about.html
in a folder named templates
with the following content:
About
About Page
This is the {{ name }}.
python app.py
.http://127.0.0.1:5000/
for the home page and http://127.0.0.1:5000/about
for the
about page.