Another short-URL generator, based on Hashids and a reduced alphabet.
Why a reduced alphabet?
Because if you’re going to bother with a short URL, it needs to be readable and easily audible, without constantly double-checking you’ve not misread or misheard.
Why Hashids
Because assuming your model primary keys are integers, it’s a dirt simple way of encoding a tuple in a reasonably small space. One could also just use django.utils.http.int_to_base36 of course.
Usage
in your settings module:
INSTALLED_APPS = (
# ...
'urlbrevity',
# ...
)
in your root urlconf:
from django.conf.urls import patterns, url, include
import urlbrevity
urlpatterns = patterns("",
# ...
url(r'redirect/', include(urlbrevity.redirects)),
# Or if you don't want to redirect ...
url(r'no_redirect/', include(urlbrevity.no_redirects)),
# ...
)
in your templates:
{% load urlbrevity %}
<a href="{% url 'urlbrevity:short' my_model_instance|hashid %}">...</a>
or ...
<a href="{{ my_model_instance|short_url }}">
in your python:
import urlbrevity
obj = MyModel.objects.get(pk='...')
encoded = urlbrevity.encode_model_instance(obj=obj)
value = encoded.hash
url = reverse('urlbrevity:short', kwargs={'encoded_value': value})
# or ...
url2 = urlbrevity.short_url(obj)
# to re-inflate ...
obj_again = urlbrevity.decode_model_instance(value)
Why internal redirects?
Because mobile is an important space, and even on 3G+ connections, redirects are another round-trip that may fail or be slow. Easier to just render the intended output if possible.
License
django-urlbrevity is available under the terms of the Simplified BSD License (alternatively known as the FreeBSD License, or the 2-clause License):
Copyright (c) 2014, Keryn Knight All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.
Metadata
Release files for django-urlbrevity 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-urlbrevity-0.1.0.tar.gz | 10.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_urlbrevity-0.1.0-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 29.9 kB
Release files / django-urlbrevity-0.1.0.tar.gz
| Download URL | django-urlbrevity-0.1.0.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2dd081dac39ac6a8bc70849219770c34ff548065ad2a047af50ce086d1c24b42
|
|
BLAKE2b-256 checksum How to use checksums |
f949a168d2f42db9039fdaaadb6d3ed425360cc2cbe6c668beb9d79da5b3dc1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_urlbrevity-0.1.0-py2-none-any.whl
| Download URL | django_urlbrevity-0.1.0-py2-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
a66c7483dd8fa22ebd6e3743abeeab3d061af8dfbc0934cb62d321e5e84b094a
|
|
BLAKE2b-256 checksum How to use checksums |
3f2e7b9e98b204e2dd901cbdf5f3448e213a1a9847a3e0e6ef824eb7ffe6f49e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-urlbrevity 0.1.0
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.