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
Rationale
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.
Usage
Modify your settings.py to include the list of words you want to use as keywords:
# settings.py URL_KEYWORDS = ('new', edit', 'delete')
Then add the validator to your slug field:
# models.py from urlkeyword import validate_url_keyword class Village(Model): code = models.SlugField(max_length=20, validators=[validate_url_keyword])
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
File details
Details for the file django-urlkeyword-0.1.1.tar.gz
.
File metadata
- Download URL: django-urlkeyword-0.1.1.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18a87469599c170529b646ec6249b8872bfb416286f7367c71eca3f0e597d127 |
|
MD5 | 364932e6e193fecff731dcf8bf7dbf9a |
|
BLAKE2b-256 | 53d3e83600e837601377b2ed5be3189260954800bd91f39bda3e2d3ceaa20d05 |