A Django URL shortener app is a web application that generates short, customized links that redirect to longer URLs. It uses Django and a database to store original and short URLs, and may incorporate third-party services for URL shortening. The app is useful for simplifying the sharing of links online.
Server: Python, Django, Django Rest Framework, Pytest, Docker, Postgres
Clone the project
git clone git@github.com:martynawitkowska/url_shortener.git
Go to the project directory
cd url_shortener
Set environmental variables
Instructions for setting variables
cp ./envs/api.default.env ./envs/api.env
cp ./envs/postgres.default.env ./envs/postgres.env
# set variable values
Start Docker Containers
docker compose up
Load test data
docker compose exec api python manage.py loaddata fixtures/test_links.json
Go to your client and type
http://0.0.0.0:8000/api/schema/swagger-ui/
Here are links from test data file that you can visit:
- http://0.0.0.0:8000/Nhd8rcbaSYUBhJKLq9fiGQ
- http://0.0.0.0:8000/fdMYv5SadxMZ8TrEzfR3y9
- http://0.0.0.0:8000/4KosSjJwwdXgT49pGWuARc
To run this project, you will need to add the following environment variables to your ./envs/api.env file
DJ_SECRET_KEY= # Django Secret Key for CSRF link
DJ_DEBUG= # Production development mode
DJ_ALLOWED_HOSTS= # Allowed Hosts for Django
DJ_SU_NAME= # Default superusername
DJ_SU_EMAIL= # Default superuser email
DJ_SU_PASSWORD= # Default superuser password
Generating DJ_SECRET_KEY in console or here secret key generator:
from django.core.management.utils import get_random_secret_key
get_random_secret_key()
Postgres variables ./envs/postgres.env
POSTGRES_USER= # Postgres root user
POSTGRES_PASSWORD= # Postgres root password
POSTGRES_DB= # Database name
POSTGRES_HOST= # Database host: set to docker compose swervice name
POSTGRES_PORT= # Database port
DB_CONNECTION_STRING=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
To run tests, run the following command
docker compose exec api pytest