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.
- Install via pip
$ pip install django-profanity-filter
- Add
'profanity',
to yourINSTALLED_APPS
insettings.py
INSTALLED_APPS = (
...
'profanity',
...
)
At the top of every template you wish to use profanity filters and tags on, make sure to load the profanity tags.
...
{% load profanity %}
...
{% with string='You are a bitch!' %}
{{ string|censor }}
{% endwith %}
The output will be You are a *****!
, instead of You are a bitch!
.
{% with string='You are a bitch!' %}
{{ string|is_profane }}
{% endwith %}
The output will be True
, since the string contains profanity.
from profanity.validators import validate_is_profane
class Post(models.Model):
post = models.TextArea(max_length=150, validators=[validate_is_profane])
- Basic filter
- Advanced filter
- Keyword argument for custom word filter
- Basic Censorship Validator