A Django-based web application that allows users to shorten long URLs into shorter, easy-to-share links. This project demonstrates model design, form handling, and basic analytics for tracking URL usage.
- URL shortening: Converts long URLs into concise, unique short links.
- Redirection: Redirects users from short links to the original URLs.
- Tracking analytics: Records how many times a short URL has been visited.
- Admin interface: Manage and view shortened URLs via Django admin.
- Form validation: User-friendly Django forms for URL input.
- Random code generation: Ensures unique short links for each URL.
- Python 3.6+
- Django 3.x
-
Clone the repository
git clone https://github.com/SulemanMughal/url-shortner.git cd url-shortner/url_shortner
-
Install dependencies
pip install django
-
Apply migrations
python manage.py migrate
-
Run the server
python manage.py runserver
-
Open in browser
- Visit
http://127.0.0.1:8000/
to access the URL shortener.
- Visit
- Enter a long URL in the form and submit.
- Receive a shortened URL to share.
- When the short URL is visited, users are redirected to the original link.
- The number of times each short URL is followed is tracked.
url_shortner/
├── manage.py
├── url_shortner/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
├── urlshortener/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── migrations/
│ ├── models.py
│ ├── templates/
│ ├── tests.py
│ ├── urls.py
│ ├── utils.py
│ └── views.py
- Model (
Shortener
): Stores original and short URLs, creation date, and visit count. - Views:
home_view
— handles the form for submitting long URLs and displaying the result.redirect_url_view
— handles redirection from short to long URLs and increments visit count.
- Forms: Django forms for URL input and validation.
- Utilities: Random code generator for creating unique short URLs.
- Templates: Responsive HTML (Bootstrap) for UI.
- Run
python manage.py createsuperuser
to create an admin account. - Visit
/admin
to manage short URLs.
- By default, uses SQLite for storage.
- Adjust settings in
url_shortner/settings.py
as needed.
MIT License