A simple Django Url Shortener.
Project description
django-link-shortener
django-link-shortener is a Django app for creating time-limited and usage-capped short URLs.
Features
- Generate short links for URLs.
- Time-sensitive links (configurable lifespan).
- Usage-limited links (configurable maximum uses).
- Per-user override of default settings via Django admin.
- Test endpoint for easy shortcode creation during development.
- Character set for shortcodes excludes I, i, 1.
Usage
-
Install with
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. -
Use
shortener.create(user, link)
to generate a shortcode.from shortener import shortener user = User.objects.first() shortener.create(user, "https://example.com")
-
To expand the shortcode use
shortener.expand(shorlink_id)
, or visithttp://127.0.0.1:8000/s/<shortcode>/
.
Test Endpoint
-
To enable the test endpoint, 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. -
Visit
http://127.0.0.1:8000/s/<shortcode>/
to be redirected
Configuration Options
Place in settings.py. Each setting can be overridden on a per-user basis using the UrlProfile section in the Django admin.
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 on authenticated requests to s/test/<url>/
and returns a 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. 100 active links with a lifespan of 1 hour. 1 usage per link.
SHORTENER_ENABLED = True
SHORTENER_MAX_URLS = -1
SHORTENER_MAX_CONCURRENT = 100
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_link_shortener-1.0.1.tar.gz
.
File metadata
- Download URL: django_link_shortener-1.0.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
0aa36a18fe74208e1a04b94835f8afbf70270a308f90cabad2628b1d80584571
|
|
MD5 |
0db5fb624c63afe79a9ef763bf07d3d5
|
|
BLAKE2b-256 |
65ca5aaffcc734f5a1117ffe5d6931243318de6a1ecc7707d96887d48f704934
|
Provenance
The following attestation bundles were made for django_link_shortener-1.0.1.tar.gz
:
Publisher:
pypi-publish.yml
on ronaldgrn/django-link-shortener
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
django_link_shortener-1.0.1.tar.gz
-
Subject digest:
0aa36a18fe74208e1a04b94835f8afbf70270a308f90cabad2628b1d80584571
- Sigstore transparency entry: 268127057
- Sigstore integration time:
-
Permalink:
ronaldgrn/django-link-shortener@94af61213a4956fa24dca1ff12f0d97965411deb
-
Branch / Tag:
refs/tags/v1.0.1
- Owner: https://github.com/ronaldgrn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
pypi-publish.yml@94af61213a4956fa24dca1ff12f0d97965411deb
-
Trigger Event:
release
-
Statement type:
File details
Details for the file django_link_shortener-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_link_shortener-1.0.1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
568e30ba1bb195df59085d64de1300a3fecb65ef628ffbb15f0ee6a9d8894327
|
|
MD5 |
defe910c3d4d918d508ae9b541a5d017
|
|
BLAKE2b-256 |
9a366504a205241b1e567d9027754a64037d74f34be0527dd3d4296ddabda3eb
|
Provenance
The following attestation bundles were made for django_link_shortener-1.0.1-py3-none-any.whl
:
Publisher:
pypi-publish.yml
on ronaldgrn/django-link-shortener
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
django_link_shortener-1.0.1-py3-none-any.whl
-
Subject digest:
568e30ba1bb195df59085d64de1300a3fecb65ef628ffbb15f0ee6a9d8894327
- Sigstore transparency entry: 268127066
- Sigstore integration time:
-
Permalink:
ronaldgrn/django-link-shortener@94af61213a4956fa24dca1ff12f0d97965411deb
-
Branch / Tag:
refs/tags/v1.0.1
- Owner: https://github.com/ronaldgrn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
pypi-publish.yml@94af61213a4956fa24dca1ff12f0d97965411deb
-
Trigger Event:
release
-
Statement type: