fixed missing db and updated instructions in README
This commit is contained in:
parent
d27449c468
commit
6d4bf67d5a
39
README.md
39
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:
|
```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
|
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
|
||||||
|
|||||||
13
app.py
13
app.py
@ -2,13 +2,24 @@ from flask import Flask, render_template, redirect, url_for, request
|
|||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user
|
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SECRET_KEY'] = 'your-secret-key-here'
|
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
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
db = SQLAlchemy(app)
|
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 = LoginManager(app)
|
||||||
login_manager.login_view = 'login'
|
login_manager.login_view = 'login'
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user