Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

DO NOT USE!

This project is no longer maintained.

It was originally made to replicate the style of URL you find on many websites to obfuscate integer based primary keys. However the implementation relies on expensive database lookups to prevent collisions.

A better/modern alternative to this project would be something using sqids.

django-randomslugfield

Django field that automatically generates random slugs.

e.g. example.com/kEwD58P

Tested with Python 2.7, 3.3+ and Django 1.4+.

Getting it

To install django-randomslugfield:

    $ pip install django-randomslugfield

Install

To enable randomslugfield in your project you need to add it to INSTALLED_APPS in your projects settings.py file:

    INSTALLED_APPS = (
        ...
        'randomslugfield',
        ...
    )

Usage

Import RandomSlugField and use it in your model:

    from django.db import models
    from randomslugfield import RandomSlugField

    class MyModel(models.Model):
        slug = RandomSlugField(length=7)

The length argument is required.

Advanced Usage

By default randomslugfield generates its slug using these characters:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

You can optionally exclude lowercase/uppercase/digits/vowels using exclude_lower=True, exclude_upper=True, exclude_digits=True, exclude_vowels=True.

You cannot exclude all characters.

Example:

    class MyModel(models.Model):
        slug = RandomSlugField(length=7, exclude_lower=True)

The total number of unique slugs is determined by characters^length.

    62^9 = 13,537,086,546,263,552 possible slugs
    62^8 = 218,340,105,584,896 possible slugs
    62^7 = 3,521,614,606,208 possible slugs
    62^6 = 56,800,235,584 possible slugs
    62^5 = 916,132,832 possible slugs

Metadata

Release files for django-randomslugfield 0.3.0.post1

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-randomslugfield 0.3.0.post1
File Size Uploaded Provenance Actions
django_randomslugfield-0.3.0.post1.tar.gz 5.5 kB Without provenance Details for django_randomslugfield-0.3.0.post1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-randomslugfield 0.3.0.post1
File Interpreter ABI Platform Actions
django_randomslugfield-0.3.0.post1-py3-none-any.whl Python 3 none any Details for django_randomslugfield-0.3.0.post1-py3-none-any.whl

Total release size: 12.3 kB

Release files / django_randomslugfield-0.3.0.post1.tar.gz

Download URL django_randomslugfield-0.3.0.post1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1056c0c8f863a631864112c06db070e5a6961d502d84982ddd3e21266deb67b7
BLAKE2b-256 checksum
How to use checksums
d4d5aaebc8e7dacb1a26a6c1e9422c2ad52a8c152c9ae0ba0deb703c0876939f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / django_randomslugfield-0.3.0.post1-py3-none-any.whl

Download URL django_randomslugfield-0.3.0.post1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4055447c5fc691fc76bb53e79db614ae9cd599c790ad208d6123a2f853976332
BLAKE2b-256 checksum
How to use checksums
d426feae8491a3411ee2bea7d81dbbcd37073aaae8ddb7f0a9055eab568ecfdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for django-randomslugfield 0.3.0.post1

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
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