{"id":13415700,"url":"https://github.com/marksweb/django-bleach","last_synced_at":"2025-04-04T17:08:24.366Z","repository":{"id":37251660,"uuid":"167435264","full_name":"marksweb/django-bleach","owner":"marksweb","description":"Bleach is a Python module that takes any HTML input, and returns valid, sanitised HTML that contains only an allowed subset of HTML tags, attributes and styles. django-bleach is a Django app that makes using bleach extremely easy.","archived":false,"fork":false,"pushed_at":"2024-05-07T01:19:30.000Z","size":207,"stargazers_count":141,"open_issues_count":16,"forks_count":22,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-05-11T22:44:57.320Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marksweb.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-24T20:47:34.000Z","updated_at":"2024-05-15T23:03:44.814Z","dependencies_parsed_at":"2024-05-15T23:13:39.980Z","dependency_job_id":null,"html_url":"https://github.com/marksweb/django-bleach","commit_stats":{"total_commits":153,"total_committers":33,"mean_commits":4.636363636363637,"dds":0.7973856209150327,"last_synced_commit":"f174f8843b091a9496fdfee2a22a552ea5c19d67"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marksweb%2Fdjango-bleach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marksweb%2Fdjango-bleach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marksweb%2Fdjango-bleach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marksweb%2Fdjango-bleach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marksweb","download_url":"https://codeload.github.com/marksweb/django-bleach/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247217184,"owners_count":20903009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T21:00:51.431Z","updated_at":"2025-04-04T17:08:24.353Z","avatar_url":"https://github.com/marksweb.png","language":"Python","funding_links":[],"categories":["Third-Party Packages"],"sub_categories":["Forms"],"readme":"django-bleach - Bleach and sanitise user HTML\n=============================================\n\n.. image:: https://readthedocs.org/projects/django-bleach/badge/?version=latest\n   :target: https://django-bleach.readthedocs.io/en/latest/?badge=latest\n   :alt: Documentation Status\n\n.. image:: http://img.shields.io/pypi/v/django-bleach.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/django-bleach/\n    :alt: Latest Version\n\n.. image:: http://img.shields.io/pypi/l/django-bleach.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/django-bleach/\n    :alt: License\n\n.. image:: http://img.shields.io/pypi/dm/django-bleach.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/django-bleach/\n    :alt: Downloads\n\n|\n\n.. image:: https://codecov.io/gh/marksweb/django-bleach/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/marksweb/django-bleach\n\n.. image:: https://api.codacy.com/project/badge/Grade/c34f923ab0a84a6f96728866c749d511\n   :alt: Codacy Badge\n   :target: https://app.codacy.com/app/marksweb/django-bleach?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=marksweb/django-bleach\u0026utm_campaign=Badge_Grade_Dashboard\n\n.. image:: https://results.pre-commit.ci/badge/github/marksweb/django-bleach/master.svg\n   :target: https://results.pre-commit.ci/latest/github/marksweb/django-bleach/master\n   :alt: pre-commit.ci status\n\n.. image:: https://img.shields.io/lgtm/grade/python/g/marksweb/django-bleach.svg?logo=lgtm\u0026logoWidth=18\n   :target: https://lgtm.com/projects/g/marksweb/django-bleach/context:python\n   :alt: Language grade: Python\n\n.. image:: https://img.shields.io/lgtm/alerts/g/marksweb/django-bleach.svg?logo=lgtm\u0026logoWidth=18\n   :target: https://lgtm.com/projects/g/marksweb/django-bleach/alerts/\n   :alt: Total alerts\n\n|\n\nArchived\n========\n\nThis project has been archived because bleach is no longer supported. The supported means of sanitizing input data is the nh3 library and there's a similar package to this available:\n\nhttps://github.com/marksweb/django-nh3\n\n------------\n\nBleach_ is a Python module that takes any HTML input, and returns\nvalid, sanitised HTML that contains only an allowed subset of HTML tags,\nattributes and styles. ``django-bleach`` is a Django app that makes using\n``bleach`` extremely easy.\n\n`Read the documentation here`_.\n\nSetup\n-----\n\n1. Install ``django-bleach`` via ``pip``::\n\n    pip install django-bleach\n\n2. Add ``django-bleach`` to your ``INSTALLED_APPS``:\n\n   .. code-block:: python\n\n        INSTALLED_APPS = [\n            # ...\n            'django_bleach',\n            # ...\n        ]\n\n3. Select some sensible defaults for the allowed tags, attributes and styles;\n   and the behaviour when unknown tags are encountered. Each of these are\n   optional, and default to using the ``bleach`` defaults. See the\n   `bleach documentation`_:\n\n   .. code-block:: python\n\n        # Which HTML tags are allowed\n        BLEACH_ALLOWED_TAGS = ['p', 'b', 'i', 'u', 'em', 'strong', 'a']\n\n        # Which HTML attributes are allowed\n        BLEACH_ALLOWED_ATTRIBUTES = ['href', 'title', 'style']\n\n        # Which CSS properties are allowed in 'style' attributes (assuming\n        # style is an allowed attribute)\n        BLEACH_ALLOWED_STYLES = [\n            'font-family', 'font-weight', 'text-decoration', 'font-variant']\n\n        # Strip unknown tags if True, replace with HTML escaped characters if\n        # False\n        BLEACH_STRIP_TAGS = True\n\n        # Strip comments, or leave them in.\n        BLEACH_STRIP_COMMENTS = False\n\n4. Select the default widget for bleach fields. This defaults to\n   ``django.forms.Textarea``, but you will probably want to replace it with a\n   WYSIWYG editor, or something similar:\n\n   .. code-block:: python\n\n        # Use the CKEditorWidget for bleached HTML fields\n        BLEACH_DEFAULT_WIDGET = 'wysiwyg.widgets.WysiwygWidget'\n\n   I use `django-ckeditor`_ in my projects, but what you use is up to you.\n\nUsage\n-----\n\nIn your models\n**************\n\n``django-bleach`` provides three ways of creating bleached output. The simplest\nway of including user-editable HTML content that is automatically sanitised is\nby using the ``BleachField`` model field:\n\n.. code-block:: python\n\n    # in app/models.py\n\n    from django import models\n    from django_bleach.models import BleachField\n\n    class Post(models.Model):\n\n        title = models.CharField()\n        content = BleachField()\n\n        # ...\n\n``BleachField`` takes the following arguments, to customise the output of\n``bleach``. See the `bleach documentation`_ for their use:\n\n* ``allowed_tags``\n* ``allowed_attributes``\n* ``strip_tags``\n* ``strip_comments``\n* ``css_sanitizer``\n\nThe following argument will be deprecated in the near future:\n\n* ``allowed_styles``\n\nIn addition to the ``bleach``-specific arguments, the ``BleachField`` model field\naccepts all of the normal field attributes. Behind the scenes, it is a\n``TextField``, and accepts all the same arguments as the default ``TextField`` does.\n\nThe ``BleachField`` model field sanitises its value before it is saved to the\ndatabase and is marked safe so it can be immediately rendered in a template\nwithout further intervention.\n\nIn model forms, ``BleachField`` model field are represented with the\n``BleachField`` form field by default.\n\nIn your forms\n*************\n\nA ``BleachField`` form field is provided. This field sanitises HTML input from\nthe user, and presents safe, clean HTML to your Django application and the\nreturned value is marked safe for immediate rendering.\n\nIn your templates\n*****************\n\nIf you have a piece of content from somewhere that needs to be printed in a\ntemplate, you can use the ``bleach`` filter:\n\n.. code-block:: django\n\n    {% load bleach_tags %}\n\n    {{ some_unsafe_content|bleach }}\n\nIf filter has no arguments it uses default settings defined in your\napplication settings. You can override allowed tags by specifying them\nas a parameter to the filter:\n\n.. code-block:: django\n\n    {{ some_unsafe_content|bleach:\"p,span\" }}\n\nThere is also ``bleach_linkify`` which uses the linkify_ function of bleach\nwhich converts URL-like strings in an HTML fragment to links\n\nThis function converts strings that look like URLs, domain names and email\naddresses in text that may be an HTML fragment to links, while preserving:\n\n1. links already in the string\n2. urls found in attributes\n3. email addresses\n\n\n.. _bleach: https://github.com/mozilla/bleach\n.. _Read the documentation here: https://django-bleach.readthedocs.io/\n.. _bleach documentation: https://bleach.readthedocs.io/en/latest/clean.html\n.. _django-ckeditor: https://github.com/shaunsephton/django-ckeditor\n.. _linkify: https://bleach.readthedocs.io/en/latest/linkify.html?highlight=linkify#bleach.linkify \"linkify\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarksweb%2Fdjango-bleach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarksweb%2Fdjango-bleach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarksweb%2Fdjango-bleach/lists"}