shortener
Basic URL shortener as a Django app.
To use:
- Install using pip
pip install shortener
- Include
shortener.apps.ShortenerConfig
toINSTALLED_APPS
in your project'ssettings.py
- Add the shortener to
urls.py
.- Example:
path('s/', include('shortener.urls', namespace='shortener'))
will shorten URLs tohttps://example.com/s/<ID>
.
- Example:
python manage.py migrate
- Either add in URL shortcuts manually through Admin, or add some hook in your project to call
shortener.objects.get_or_create
. The function takes in a long URL and returns aUrl
object which contains the full shortened url asUrl.shortened
, and the slug inUrl.short_id
.