This project was born out of my curiosity for how URL Shorteners work.
This is a simple URL shortener in Flask.
Shortens URL upto length 512 characters to 6 characters.
Made using Flask-SQLAlchemy. This URL shortener will be able to redirect links and keep stats on the number of times each link was visited.
Also has HTTP Basic Authentication to view stats.
All this data will be stored in a sqlite3 database
- "link" Table in the Database
- Index page
- Short URL generated
- Statistics (Needs HTTP Authentication)
Always recommended to create a virtual environment
-
Create virtual environment and install flask
pipenv install flask
-
To start shell and enter the venv
pipenv shell
-
Dependencies:(this step might not be needed)
pipenv install python-dotenv
pipenv install sql-alchemy
-
To run the app
start shell if not started
pipenv shell
flask run
-
Start python in terminal
python
-
from url_shortener import create_app
-
from url_shortener.extensions import db
-
from url_shortener.models import Link
-
To create tables and database
db.create_all(app = create_app())
-
To exit python console
exit()
-
To view database, write in terminal
sqlite3 url_shortener/db.sqlite3
-
To see the table names in database
.tables
-
To query the database
SELECT * FROM link;
-
To delete table contents but not table
DELETE FROM link;
-
To exit sqlite3
.exit
-
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
-
Please make sure to update tests as appropriate.
-
You can also edit the readme and make it more user friendly to help out new contributors.
This project was made using GitHub Codespaces Beta. Thanks to them for providing me early access to their such beautiful and useful feature.