A tiny, easy-to-use URL shortener built with Flask and SQLite.
This project provides a minimal web app that shortens long URLs and redirects requests from the generated short path to the original URL. It uses Flask for the web app and SQLAlchemy + SQLite for persistence.
- Tech: Python, Flask, Flask-SQLAlchemy, SQLite
- Files of interest:
run.py,templates/index.html,templates/result.html
- Generate short, random URLs (default length: 6)
- Store mappings in a local SQLite database (
links.db) - Simple HTML form UI to create short links
- Python 3.8+ installed
- Git (optional)
If you cloned the repo:
git clone <repo-url>
cd "Url Shortner"Note: this repo already contains a
requirements.txtfile.
Windows (PowerShell):
python -m venv env
env\Scripts\Activate.ps1Windows (cmd.exe):
python -m venv env
env\Scripts\activate.batmacOS / Linux:
python3 -m venv env
source env/bin/activatepip install -r requirements.txtpython run.pyOpen your browser at: http://127.0.0.1:5000
- The app uses
sqlite:///links.dbby default. The database filelinks.dbis automatically created on first run. - Short codes are 6 characters (letters + digits) by default. You can change
gen_short(length=6)inrun.pyif you want different lengths. - To run in development mode with auto-reload, set
FLASK_ENV=developmentand run withflask runor editrun.pytoapp.run(debug=True)(for convenience during development).
Url Shortner/
├─ run.py # Flask app and URL model
├─ requirements.txt # Dependencies
├─ templates/
│ ├─ index.html
│ └─ result.html
├─ instance/ # Flask instance folder (if used)
└─ links.db # SQLite DB (created at runtime)
- Open the home page and paste a long URL into the form.
- Click the button to shorten; the result shows a clickable shortened URL (e.g.
http://127.0.0.1:5000/Ab4kX2). - Visiting that short path will redirect to the original long URL.
This project is licensed under the MIT License — see the LICENSE file for details.
Happy shortening! ✂️