This is a simple URL shortener web application. It is built using Django, and it allows users to input a long URL and receive a shortened version of it. Users can then use the shortened URL to be redirected to the original URL.
- Shorten a long URL
- Redirect from a shortened URL to the original URL
- View all shortened URLs
- Basic validation of URL input
- Unit tests for core functionality
- Python 3.x
-
Clone the repository:
git clone https://github.com/yourusername/url-shortener.git cd url-shortener -
Create and activate a virtual environment:
python -m venv env source env/bin/activate # On Windows use `env\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
The
requirements.txtfile should contain the following dependencies:asgiref==3.8.1 coverage==7.5.4 Django==4.2.14 sqlparse==0.5.0 typing-extensions==4.12.2 tzdata==2024.1 validators==0.32.0
-
Apply migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver
The application should now be running at
http://localhost:8000.
-
Shorten a URL:
- Navigate to
http://localhost:8000/ - Enter a long URL into the form and submit
- Receive a shortened URL in the format
http://localhost:8000/{slug}
- Navigate to
-
Redirect using a shortened URL:
- Use the shortened URL to navigate to the original URL
-
View all shortened URLs:
- Navigate to
http://localhost:8000/view_urls/to see a list of all shortened URLs
- Navigate to
To run the tests for this application, use the following command:
python manage.py testTo check the test coverage using coverage.py, follow these steps:
-
Install
coverage.py(if not already installed):pip install coverage
-
Run tests with coverage:
coverage run manage.py test -
Generate coverage report:
coverage report
This will output a coverage report in the terminal.
-
Generate HTML coverage report:
coverage html
This will create an HTML report in the
htmlcovdirectory. Openhtmlcov/index.htmlin a browser to view the detailed coverage report.