From 6d4bf67d5a893d85f0e4c63545a97493149fa105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20J=C3=B6nsson?= Date: Sat, 15 Nov 2025 18:47:14 +0100 Subject: [PATCH] fixed missing db and updated instructions in README --- README.md | 41 +++++++++++++++++++++++++++++++++++++---- app.py | 13 ++++++++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fd4f3d6..5dacf16 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,40 @@ -# flask-base +# Flask Base Application -Simple flask website with login +A simple Flask web application with user authentication features. +## Installation -To run: -pkill -f "flask run" && flask run --host=0.0.0.0 --port=5001 \ No newline at end of file +```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 + +```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 +``` + +The application will be available at `http://localhost:5001` + +## Features +- User registration with password confirmation +- Secure password hashing +- Login/logout functionality +- SQLite database diff --git a/app.py b/app.py index 23e0f1d..08c5cd9 100644 --- a/app.py +++ b/app.py @@ -2,13 +2,24 @@ from flask import Flask, render_template, redirect, url_for, request from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user from werkzeug.security import generate_password_hash, check_password_hash +import os app = Flask(__name__) app.config['SECRET_KEY'] = 'your-secret-key-here' -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///instance/users.db' +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(os.path.abspath(os.path.dirname(__file__)), 'instance/users.db') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) + +# Initialize database CLI command +@app.cli.command("init-db") +def init_db(): + import os + db_path = app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '') + os.makedirs(os.path.dirname(db_path), exist_ok=True, mode=0o755) + with app.app_context(): + db.create_all() + print(f"Database created at {db_path}") login_manager = LoginManager(app) login_manager.login_view = 'login'