Added readme
This commit is contained in:
@@ -4,13 +4,13 @@ A complete full-stack web application with user authentication built with Flask
|
||||
|
||||
## 📁 Project Structure
|
||||
flask_app/
|
||||
├── app.py # Main Flask application
|
||||
├── database.py # Database setup and functions
|
||||
├── users.py # User authentication functions
|
||||
├── users.db # SQLite database
|
||||
├── requirements.txt # Python dependencies
|
||||
├── venv/ # Virtual environment
|
||||
└── templates/ # HTML templates
|
||||
├── app.py
|
||||
├── database.py
|
||||
├── users.py
|
||||
├── users.db
|
||||
├── requirements.txt
|
||||
├── venv/
|
||||
└── templates/
|
||||
├── base.html
|
||||
├── home.html
|
||||
├── login.html
|
||||
@@ -20,15 +20,37 @@ text
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### 1. Create Project Structure
|
||||
### 1. Create Project Scaffold (One Command!)
|
||||
|
||||
```bash
|
||||
cd Desktop
|
||||
mkdir flask_app
|
||||
# Create all empty files and folders with one command:
|
||||
mkdir -p flask_app/templates && cd flask_app && touch app.py database.py users.py users.db requirements.txt && mkdir -p venv && touch templates/base.html templates/home.html templates/login.html templates/register.html && cd .. && echo "✅ All empty files created in 'flask_app/':" && find flask_app/ -type f | sort
|
||||
2. Setup Virtual Environment
|
||||
bash
|
||||
cd flask_app
|
||||
|
||||
# Create all project files at once
|
||||
cat > app.py << 'PYEOF'
|
||||
# Create virtual environment
|
||||
python -m venv venv
|
||||
|
||||
# Activate virtual environment (Windows PowerShell)
|
||||
venv\Scripts\Activate.ps1
|
||||
|
||||
# If you get an error:
|
||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
venv\Scripts\Activate.ps1
|
||||
|
||||
# Activate virtual environment (Mac/Linux)
|
||||
# source venv/bin/activate
|
||||
3. Install Dependencies
|
||||
bash
|
||||
pip install flask werkzeug flask-wtf
|
||||
pip freeze > requirements.txt
|
||||
4. Fill Files with Code
|
||||
Now fill the empty files with the code below:
|
||||
|
||||
app.py - Main Flask application:
|
||||
|
||||
python
|
||||
from flask import Flask, render_template, request, redirect, url_for, session, flash
|
||||
import database
|
||||
import users
|
||||
@@ -85,9 +107,9 @@ def logout():
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
PYEOF
|
||||
database.py - Database operations:
|
||||
|
||||
cat > database.py << 'DBEOF'
|
||||
python
|
||||
import sqlite3
|
||||
|
||||
def init_db():
|
||||
@@ -111,9 +133,9 @@ def get_db_connection():
|
||||
conn = sqlite3.connect('users.db')
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
DBEOF
|
||||
users.py - User authentication:
|
||||
|
||||
cat > users.py << 'UEOF'
|
||||
python
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
import database
|
||||
|
||||
@@ -139,12 +161,10 @@ def login_user(username, password):
|
||||
return True, user
|
||||
else:
|
||||
return False, 'Invalid username or password!'
|
||||
UEOF
|
||||
5. Fill HTML Templates
|
||||
templates/base.html:
|
||||
|
||||
# Create templates folder
|
||||
mkdir templates
|
||||
|
||||
cat > templates/base.html << 'HTML1EOF'
|
||||
html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -184,9 +204,9 @@ cat > templates/base.html << 'HTML1EOF'
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
HTML1EOF
|
||||
templates/home.html:
|
||||
|
||||
cat > templates/home.html << 'HTML2EOF'
|
||||
html
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Home{% endblock %}
|
||||
@@ -201,9 +221,9 @@ cat > templates/home.html << 'HTML2EOF'
|
||||
<p>Please <a href="{{ url_for('login') }}">login</a> or <a href="{{ url_for('register') }}">register</a>.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
HTML2EOF
|
||||
templates/register.html:
|
||||
|
||||
cat > templates/register.html << 'HTML3EOF'
|
||||
html
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Register{% endblock %}
|
||||
@@ -218,9 +238,9 @@ cat > templates/register.html << 'HTML3EOF'
|
||||
</form>
|
||||
<p>Already have an account? <a href="{{ url_for('login') }}">Login here</a></p>
|
||||
{% endblock %}
|
||||
HTML3EOF
|
||||
templates/login.html:
|
||||
|
||||
cat > templates/login.html << 'HTML4EOF'
|
||||
html
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Login{% endblock %}
|
||||
@@ -234,21 +254,7 @@ cat > templates/login.html << 'HTML4EOF'
|
||||
</form>
|
||||
<p>Don't have an account? <a href="{{ url_for('register') }}">Register here</a></p>
|
||||
{% endblock %}
|
||||
HTML4EOF
|
||||
2. Create Virtual Environment
|
||||
bash
|
||||
python -m venv venv
|
||||
venv\Scripts\Activate.ps1
|
||||
If you get an error:
|
||||
|
||||
bash
|
||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
venv\Scripts\Activate.ps1
|
||||
3. Install Dependencies
|
||||
bash
|
||||
pip install flask werkzeug flask-wtf
|
||||
pip freeze > requirements.txt
|
||||
4. Run the Application
|
||||
6. Run the Application
|
||||
bash
|
||||
python app.py
|
||||
Visit: http://127.0.0.1:5000
|
||||
|
||||
Reference in New Issue
Block a user