Flask Base Application
A simple Flask web application with user authentication features.
Installation
# Clone the repository
git clone https://git.leoan.se/andreas/flask-base.git
cd flask-base
# Create and activate virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Linux/MacOS
# venv\Scripts\activate # On Windows
# Install dependencies
pip install flask flask-sqlalchemy flask-login werkzeug
# Initialize database
flask init-db
Usage
Local Development
# Start development server
flask run --host=0.0.0.0 --port=5001
# Optional: Kill any existing flask server first
pkill -f "flask run" && flask run --host=0.0.0.0 --port=5001
Docker Deployment
# First generate and set your secret key
python -c 'import secrets; print(f"FLASK_SECRET_KEY={secrets.token_hex(32)}")' >> .env
# Then start the container
docker-compose up --build
# Production deployment (detached mode)
docker-compose up --build -d
Note: Docker will automatically load the .env file from your project root
The application will be available at http://localhost:5001
Persisting Data
The database file (database.db) will be preserved between container restarts through the ./instance volume mount.
Important: After renaming the database:
- Delete the old database file if it exists:
rm instance/users.db
- Reinitialize the database:
flask init-db
Configuration
Secret Key Management
The application uses a hierarchical configuration for the secret key:
- Environment variable
FLASK_SECRET_KEY(highest priority) - Hardcoded value in
app.py(development fallback only)
Production Setup:
# Generate a secure secret key
python -c 'import secrets; print(secrets.token_hex(32))'
# Update .env file
echo "FLASK_SECRET_KEY=your_generated_secret_here" >> .env
Important Security Notes:
- Never commit the
.envfile to version control - The default secret key should only be used for development
- In production, use proper secret management (Vault, KMS, etc.)
Features
- User registration with password confirmation
- Secure password hashing
- Login/logout functionality
- SQLite database
- Environment-based configuration
Description
Languages
HTML
66%
Python
29.4%
Dockerfile
4.6%