Flask is a "micro-framework" that provides the essentials for building web applications. Combined with Jinja2 templates, it's perfect for server-side rendered websites.
Key Concepts to Learn
- Routing: Mapping URLs to Python functions.
- Jinja2 Templating: Using
{{ variable }}and{% if %}/{% for %}in HTML. - Template Inheritance: Creating a
base.htmlto share layouts across pages. - Form Handling: Receiving data from HTML forms.
- Static Files: Serving CSS, Images, and JavaScript.
Lesson Plan
- Basic Route: Returning HTML from a function.
- Rendering Templates: Using
render_template()to show HTML files. - Dynamic Content: Passing Python lists/dicts to Jinja2.
- Forms & POST: Building a simple "Guestbook" application.
- Flash Messages: Notifying users of success or errors.
Running the Example
cd curriculum/flaskpip install -r requirements.txtpython app.py- Open
http://127.0.0.1:5000in your browser.