Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Validate that your slugs do not match a keyword in your url

Project description

Validate that your slugs do not match a keyword in your url


Suppose you have some of urls like:

  • country-of-fire/edit/
  • country-of-fire/hidden-leaf-village/
  • country-of-fire/hidden-leaf-village/edit/
  • country-of-fire/forest-of-death/
  • country-of-fire/forest-of-death/edit/

If the feudal lords of the Country of Fire decided to found a new village, you would kindly try to suggest them to avoid names like edit or delete; they probably won’t understand anything about technological constraints, but your suggestion could be nonetheless welcome.

Instead of trying to explain why it’s not a good idea to found “Edit” (though maybe “Edit Village” may be acceptable), you may just write a piece of software that will not let anybody register any place suchly named. This is called validation.


Modify your to include the list of words you want to use as keywords:


URL_KEYWORDS = ('new', edit', 'delete')

Then add the validator to your slug field:


from urlkeyword import validate_url_keyword

class Village(Model):
    code = models.SlugField(max_length=20, validators=[validate_url_keyword])

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-urlkeyword, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size django-urlkeyword-0.1.1.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page