Skip to main content

Django URL Shortner

A set of utils to build custom fully-functional Django URL Shortner. This library helps you build a custom URL Shortner service for your project without relying on external services like bitly

Quick Start

Installation

Django UrlShortner is available at the Python Packaging Index so you can Install it using pip

pip install django-urlshortner

Please dont mistake the spelling with django-urlshortener when installing. The name does not have an e in the word shortner. Its django-urlshortner not django-urlshortener

After you should add the urlshortner app to your INSTALLED_APPS in settings.py

Configuration

INSTALLED_APPS = [
    # ....
    "urlshortner"
]

Then you migrate the models to your database

python3 manage.py migrate

Lastly add the routes to your URLConf in your urls.py of your project.

url_patterns = [
    # ...
    path("r/", include("urlshortner.urls")),
]

Now you are good to go.

Usage

The library provides a list of utils to create shortened urls.

To create a short version of a url use the shorten_url function from urlshortner.utils module

# python3 manage.py shell
from urlshortner.utils import shorten_url

url_route = shorten_url(
    "https://github.com/jim-junior/django-urlshortner",
    is_permanent=False
)

print(url_route)
# >>> 0ee3f0

You can now navigate to you the route that you assigned to urlshortner.urls in your URLConf add the returned value att the end of the url. In this case it would be http://localhost:8000/r/0ee3f0/ and this would redirect you to the right URL

Sometimes you want to create a custom URL. For example you want to create a short link for a blog about your new product and you want a url that is easy to remember. You can add this easily by adding the value argument to the shorten_url function

from urlshortner.utils import shorten_url

url_route = shorten_url(
    "https://myblog.com/blog/2022/10/10/..../my-new-product",
    value="NewProduct"
    is_permanent=False
)

You can now navigate to https://localhost/r/NewProduct and It will redirect you


Licence MIT

Copyright © Beingana JIm Junior, 2022

Metadata

Release files for django-urlshortner 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-urlshortner 0.0.2
File Size Uploaded Provenance Actions
django-urlshortner-0.0.2.tar.gz 5.1 kB Without provenance Details for django-urlshortner-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-urlshortner 0.0.2
File Interpreter ABI Platform Actions
django_urlshortner-0.0.2-py3-none-any.whl Python 3 none any Details for django_urlshortner-0.0.2-py3-none-any.whl

Total release size: 12.2 kB

Release files / django-urlshortner-0.0.2.tar.gz

Download URL django-urlshortner-0.0.2.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
03247efb287e6a5df9eed2e8983aae93070d6bf71a209fb8b3904d6f355f292a
BLAKE2b-256 checksum
How to use checksums
0bb20c93edd77627a3107460956519d0783c85a94678718b19ae3499a10d7369
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / django_urlshortner-0.0.2-py3-none-any.whl

Download URL django_urlshortner-0.0.2-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7dcd839eea458a6d471b181f7927943b2b4d87e63b51e7592ce503bfdaacb469
BLAKE2b-256 checksum
How to use checksums
e7bd764f3e0eb831ac7d42bce1b01f3212b8c0190b29bd9106a1688daf23ba6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for django-urlshortner 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page