Flask Flashcards



🔥 Flask Flashcards


Flask web framework overview showing routes, templates, static files, and REST APIs

Quickly learn the Flask web framework with this friendly flashcards guide. Instead of reading a long manual, you’ll skim concise cards that explain routes, templates, sessions, REST APIs, and testing. As a result, you can move from “Hello, World!” to a clean, production-ready app much faster.

Moreover, the framework stays minimal by design. You add what you need—ORMs, authentication, caching, or background jobs—only when your project demands it. Consequently, teams appreciate the control, while solo developers enjoy the low learning curve. In practice, you’ll define URL endpoints, render pages with Jinja2, return JSON for clients, and serve static assets without fuss.

Before you begin, remember a few setup tips. First, create a virtual environment to isolate dependencies. Next, install the core package and any extensions you plan to use. Then, run your development server and iterate rapidly with auto-reload. Finally, write tests early so you can refactor with confidence as features grow.

Key Concepts at a Glance

💡 What is it?
A lightweight WSGI web framework in Python—simple core, easy to extend with libraries and patterns.
🚀 Async support?
Primarily synchronous; you can integrate asyncio patterns or use compatible frameworks like Quart for full async.
📦 Installation
Create a venv, then run pip install Flask. Pin versions in requirements.txt for reliability.
🔗 Routes
Bind functions to URLs with @app.route(). Return HTML, JSON, or redirects as needed.
🗂️ Templates
Render Jinja2 templates from a templates folder. Use blocks, filters, and macros for reuse.
🔐 Sessions
Use the signed cookie-based session object. Configure a strong SECRET_KEY and rotate keys periodically.
🧪 Testing
Leverage the built-in test client with pytest or unittest for unit and integration tests.
🌐 Building APIs
Return JSON responses, validate input, and version endpoints. Many teams add Blueprints to group routes.
🔁 Enabling CORS
Install flask-cors and apply it at the app or Blueprint level to allow cross-origin requests.
📁 Static files
Serve assets from static and reference them via url_for('static', filename='app.css').

Getting Started & Next Steps

First, scaffold a minimal app with a single route. Next, add a template for your home page, along with a stylesheet in the static folder. Then, expose a JSON endpoint for your front-end. Finally, write tests for the happy path and a couple of edge cases, so you can extend features with confidence.

As your project grows, consider Blueprints (modular routing), environment-specific configs, a production WSGI server (e.g., Gunicorn or uWSGI), and a reverse proxy like Nginx. In addition, you may adopt extensions for database access (SQLAlchemy), migrations (Alembic), authentication (Flask-Login), and caching (Flask-Caching).