Skip to content

Flask web application project demonstrating core backend concepts including routing, URL parameters, HTTP methods, Jinja2, API endpoints, etc.

License

Notifications You must be signed in to change notification settings

ignacio-serrano-rodriguez/flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask Project

1. Useful CLI commands

  • Official Documentation

  • flask --app "filename".py run

    Explicitly specifies which Python file contains your Flask application and runs it. This command is useful when:

    • Your Flask app file is not named app.py or wsgi.py (Flask's default names)
    • You have multiple Flask applications in the same directory
    • You want to be explicit about which file to run
  • flask run

    Starts the Flask development server. This command runs your Flask application locally, making it accessible at http://127.0.0.1:5000 by default.

  • flask run --debug

    Starts the Flask development server with debug mode enabled. Debug mode provides:

    • Automatic reloading: Server restarts automatically when you save code changes
    • Detailed error pages: Shows full stack traces and exact error locations in the browser
    • Interactive debugger: Click on traceback lines to open a Python console (requires PIN)
    • Enhanced logging: More verbose output in the terminal

    Security Warning: Never use debug mode in production! The interactive debugger allows code execution.

2. API Debugging Tool

HTTP POST Method

Headers

  • Content-Type: application/x-www-form-urlencoded

Body Configuration

  • Select Body tab
  • Choose x-www-form-urlencoded
  • Add key-value pairs for form fields

3. Deploying to Production

Production Server Requirements

  • Don't use Flask's built-in server in production
    • install Gunicorn or similar WSGI server
  • Flask's development server (flask run) is only for local development

Security & Configuration

  • Never hardcode API keys
    • use environment variables instead
  • Check your code before pushing to GitHub to avoid exposing secrets
  • Use .env files locally and proper environment configuration in production

Database Management

  • Properly close database connections to prevent memory leaks
  • Use SQLAlchemy's connection pooling for better performance under load
  • Monitor your database connections in production

Development Tools

  • Docker is essential, not overkill
    • simplifies deployment with docker-compose up
  • Flask-CORS quickly fixes cross-origin request issues in APIs

Quick Deployment Checklist

  • Replace Flask dev server with Gunicorn
  • Move all secrets to environment variables
  • Configure proper database connection handling
  • Set up Docker containers
  • Configure CORS if building an API

Bottom line: What works locally often breaks in production. Plan for proper production infrastructure from the start!

4. Official Documentation

About

Flask web application project demonstrating core backend concepts including routing, URL parameters, HTTP methods, Jinja2, API endpoints, etc.

Topics

Resources

License

Stars

Watchers

Forks

Contributors