A simple Django Url Shortener.
Project description
django-link-shortener is a simple time and usage sensitive url shortening app.
Uses A-Za-z0-9 with the exception of I, i and 1.
Requires user to be logged in for link creation.
Usage
pip install django-link-shortener
Add ‘shortener’ to your INSTALLED_APPS setting:
INSTALLED_APPS = [ ... 'shortener', ]
Include shortener.urls in your project urls.py:
path('s/', include('shortener.urls')),
Run python manage.py migrate to create the shortener models.
Testing
Add the following to settings
` SHORTENER_ENABLE_TEST_PATH = True `
Start the development server and visit http://127.0.0.1:8000/s/test/<My-URL-HERE> to create a test shortcode.
or
Use shortener.create(user, link) to generate a link via code. Use shortener.expand(link) to revert
Visit http://127.0.0.1:8000/s/<shortcode>/ to be redirected
Configuration Options
Place in settings.py. Each setting be overridden on a per-user basis using the admin UrlProfile section
- SHORTENER_ENABLED
Default: True
Controls whether users without a shortener profile can create shortlinks.
- SHORTENER_MAX_URLS
Default: -1
Controls the default maximum limit of generated urls per account. -1 sets infinite.
- SHORTENER_MAX_CONCURRENT
Default: -1
Controls the default maximum limit of concurrent (active) generated urls per account. -1 sets infinite
- SHORTENER_LIFESPAN
Default: -1
Sets the default lifespan of links in seconds -1 sets infinite
- SHORTENER_MAX_USES
Default: -1
Sets the default amount of times a link can be followed -1 sets infinite
- SHORTENER_LENGTH
Default: 5
Note: Omitted from UrlProfile
Sets how many digits should be used for links. Tries up to three times to generate a unique shortcode where Each failure will result in length temporarily being increased by 1.
- SHORTENER_ENABLE_TEST_PATH
Default: False
If true, creates shortlinks for logged in users at s/test/<<url>>/
The response is the shortcode to use used at s/<<shortcode>>
Common Use Cases
goo.gl type usage (default). Unlimited concurrent links for an unlimited length of time
SHORTENER_ENABLED = True SHORTENER_MAX_URLS = -1 SHORTENER_MAX_CONCURRENT = -1 SHORTENER_LIFESPAN = -1 SHORTENER_MAX_USES = -1
Internal temporary link usage (such as on nodeferret.com). 100 Temp links per minute. 1 usage per link.
SHORTENER_ENABLED = True SHORTENER_MAX_URLS = -1 SHORTENER_MAX_CONCURRENT = 100 # To prevent spamming SHORTENER_LIFESPAN = 600 SHORTENER_MAX_USES = 1
Changelog
v0.5
Replaced NullBooleanField with BooleanField (Credit: sen-den)
Replaced travis-ci with github actions
v0.4
Allow null values in UrlProfile; null fields will use global values
str representation of UrlProfile in admin
add user to str representation of UrlMap
removed 256 char limit on full_url (Credit: Khaeshah)
Upgrade Instructions
0.3 / 0.4 –> 0.5
pip install django-link-shortener==0.5 python manage.py migrate
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file django_link_shortener-0.5-py3-none-any.whl
.
File metadata
- Download URL: django_link_shortener-0.5-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2515ab542ca0460d1cda8984626c0fd3d2e8b2f1f2aa444cd469d7b19244495 |
|
MD5 | 1190be7b24c85af2cb4c78e574aba43b |
|
BLAKE2b-256 | 8e20dec96abc0ce2a0e58a1f96a88ea8bbb66d3afb4209f6dab6f8ce97fc8926 |