skillfed

django-bleach

Easily use bleach with Django models and templates

django-bleach v3.1.0 105.8K downloads/30d#12,679 on PyPI149
Permissive license MIT Abandoned released

What it is and what it does

django-bleach wraps bleach to make HTML sanitization a first-class feature in Django applications. It provides a BleachField model field that automatically sanitizes HTML before saving to the database, a corresponding form field for user input, and template filters for rendering untrusted content safely. The package lets you define allowed HTML tags, attributes, and CSS styles through Django settings, then applies those rules consistently across your application.

The core problem it solves is preventing XSS attacks and malformed HTML when accepting user-generated content. Instead of storing raw HTML or stripping all markup, django-bleach preserves semantic tags while removing script tags, event handlers, and other dangerous constructs. It integrates directly into Django's ORM and form layer, so sanitization happens automatically without extra middleware or view-level logic.

Use it for:

  • Blog or CMS platforms where users write posts with basic formatting but you need to prevent script injection
  • Comment systems that allow limited HTML markup while blocking malicious content
  • User profile descriptions or bio fields that should support simple rich text
  • Converting URL-like strings to links in user-submitted text using the bleach_linkify filter
  • Rendering third-party or legacy HTML content in templates without exposing your application to embedded attacks

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Integrates bleach HTML sanitization into Django models, forms, and templates to strip unsafe HTML tags and attributes from user input while preserving safe markup.

No. The repository is archived and abandoned with no maintenance since 2023-08-05. While the code is stable and currently compatible with Django 3.2–4.2, there is no path forward for security patches, Django 5.0+ support, or bleach library updates. For new projects, use an actively maintained alternative or apply bleach directly in your views. For existing projects still on supported Django versions, it remains functional but carries increasing technical debt.

Install

django-bleach on PyPI

pip

pip install django-bleach

uv

uv add django-bleach

poetry

poetry add django-bleach

Installing django-bleach

Before you install

Low install friction with a pure-Python wheel. However, the repository is archived and abandoned as of 1105 days since last release, with the latest version from 2023-08-05. No active maintenance means security updates are unlikely.

License in practice

MIT license is permissive and imposes no restrictions on use, modification, or distribution in commercial or private projects.

Quickstart

pip install django-bleach

# In settings.py
INSTALLED_APPS = ['django_bleach']
BLEACH_ALLOWED_TAGS = ['p', 'b', 'i', 'u', 'em', 'strong', 'a']

# In models.py
from django_bleach.models import BleachField
class Post(models.Model):
    content = BleachField()

Verify before relying

  • Whether bleach itself receives active security updates and how that affects django-bleach's viability
  • Compatibility with Django versions beyond 4.2 given the abandoned status
  • Real-world performance impact of sanitization on high-volume user input

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 2 — bleach, Django
Maintenance abandoned — 1,105 days since the last release
Last repo commit (repository archived)
First released
Downloads 105,784/month — #12,679 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_bleach-3.1.0-py2.py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: Django :: 3.2Framework :: Django :: 4.0Framework :: Django :: 4.1Framework :: Django :: 4.2Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

django html sanitizationbleach integration djangouser html input cleaningxss prevention djangosafe html rendering djangohtml tag filteringdjango content sanitizer
html-sanitizationsecurityabandoned

More Dynamic Content packages