91 lines
2.2 KiB
Markdown
91 lines
2.2 KiB
Markdown
# Flask Base Application
|
|
|
|
A simple Flask web application with user authentication features.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
# 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
|
|
```bash
|
|
# 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
|
|
```bash
|
|
# 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:
|
|
1. Delete the old database file if it exists:
|
|
```bash
|
|
rm instance/users.db
|
|
```
|
|
2. Reinitialize the database:
|
|
```bash
|
|
flask init-db
|
|
```
|
|
|
|
## Configuration
|
|
|
|
### Secret Key Management
|
|
The application uses a hierarchical configuration for the secret key:
|
|
1. Environment variable `FLASK_SECRET_KEY` (highest priority)
|
|
2. Hardcoded value in `app.py` (development fallback only)
|
|
|
|
**Production Setup:**
|
|
```bash
|
|
# 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 `.env` file 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
|