django-profanity-filter
django-profanity-filter copied to clipboard
Django profanity template filter and validators
Django Profanity Filter
Django Profanity Filter is a simple Django app that introduces a range of template tags and filters and model validators that remove or censor inappropriate language.
Installation
- Install via pip
$ pip install django-profanity-filter
- Add
'profanity',to yourINSTALLED_APPSinsettings.py
INSTALLED_APPS = (
...
'profanity',
...
)
Usage
Template Tags
At the top of every template you wish to use profanity filters and tags on, make sure to load the profanity tags.
...
{% load profanity %}
...
Censor Filter
Example
{% with string='You are a bitch!' %}
{{ string|censor }}
{% endwith %}
The output will be You are a *****!, instead of You are a bitch!.
Is Profane Tag
Example
{% with string='You are a bitch!' %}
{{ string|is_profane }}
{% endwith %}
The output will be True, since the string contains profanity.
Validators
Is Profane Validator
Example
from profanity.validators import validate_is_profane
class Post(models.Model):
post = models.TextArea(max_length=150, validators=[validate_is_profane])
TODO
Template Tags
- [x] Basic filter
- [ ] Advanced filter
- Keyword argument for custom word filter
Validators
- [x] Basic Censorship Validator