Basic URL shortener powered by Django Web Framework.
https://django-shortener.herokuapp.com/
First launch may take a couple of seconds. Further interaction should be quicker.
- Enter URL on the main page and press Enter
- Copy short URL from the result page
- ???
- Profit!
There is more than one way to deploy this to Heroku. Feel free to deviate from the instructions if you know how to do it better.
- Clone this repo to the local machine
git clone https://github.com/deniskasyanov/django-shortener
- Install Heroku CLI and log in to your Heroku account in shell (instructions on Heroku website)
- Attach Heroku PostgreSQL addon using
heroku addons:add heroku-postgresql
. This will automatically set environment variableDATABASE_URL
- Set up remaining environment variables according to the next subsection
- Push the repo to Heroku:
git push heroku master
- Run database migrations with
heroku run python manage.py migrate
ADMIN_URL_PATH
- Admin will be available at
https://<YOUR_PROJECT>.herokuapp.com/<ADMIN_URL_PATH>/
- Admin will be available at
DATABASE_URL
- Heroku will most likely set it up automatically. Should be set up manually in development environment though. Format is
postgres://<USER>:<PASSWORD>@<HOSTNAME>:<PORT>/<DATABASE_NAME>
. For example, I used something likepostgres://user:password@localhost/django_shortener
for local development (port is omitted)
- Heroku will most likely set it up automatically. Should be set up manually in development environment though. Format is
DEBUG
- Should contain
false
in production environment andtrue
in development one
- Should contain
DJANGO_SETTINGS_MODULE
shortener.settings.production
for production andshortener.settings.local
for development
SECRET_KEY
- It is probably a good idea to have different secret keys for development and production. See SECRET_KEY section in Django Deployment Checklist
Environment variables can be set up in web interface (Project Setting -> Config Variables) or using Heroku CLI as follows:
heroku config:set <ENVIRONMENT_VARIABLE>=<VALUE>
There are convenience utility scripts in local_env_vars/
for setting and unsetting environment variables in local environment. You need to change at least DATABASE_URL
with your DB config, everything else should work even with default values. Run . local_env_vars/set.sh
from project root to set up variables and . local_env_vars/unset.sh
to unset them.
- Static files are served with Python
- Should not be a big problem since all public-facing pages use only Bootstrap hosted on CDN or inline 9-line JS for one-click copying. If new features requiring custom static files are added, assets can be moved to S3 or similar service
- JS is inline
- Well, it's only 9 lines. I don't plan to add new features, so I've decided not to alter settings and create additional nested folder structure just for one simple script.
- Features that can be added to enhance user experience and increase security:
- Click counting
- Rate limiting for anonymous users
- As a result, user registration and authentication
- API