Django Mozilla



Latest version

With Django, you can take Web applications from concept to launch in a matter of hours. Django takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

  • Django’s primary goal is to ease the creation of complex database-driven websites. Some well known sites that use Django include PBS, Instagram, Disqus, Washington Times, Bitbucket and Mozilla. What will you find here? If you’re new to Django, we recommend starting with the Real Python course to get a firm foundation in web development in.
  • Django offers full support for translating text into different languages, plus locale-specific formatting of dates, times, numbers, and time zones. It lets developers and template authors specify which parts of their apps should be translated or formatted for local languages and cultures, and it uses these hooks to localize Web applications for.

Released:

Easily use bleach with Django models and templates

Project description

Bleach is a Python module that takes any HTML input, and returnsvalid, sanitised HTML that contains only an allowed subset of HTML tags,attributes and styles. django-bleach is a Django app that makes usingbleach extremely easy.

Setup

  1. Install django-bleach via pip:

  2. Add django-bleach to your INSTALLED_APPS:

  3. Select some sensible defaults for the allowed tags, attributes and styles;and the behaviour when unknown tags are encountered. Each of these areoptional, and default to using the bleach defaults. See thebleach documentation:

  4. Select the default widget for bleach fields. This defaults todjango.forms.Textarea, but you will probably want to replace it with aWYSIWYG editor, or something similar:

    I use django-ckeditor in my projects, but what you use is up to you.

Usage

In your models

django-bleach provides three ways of creating bleached output. The simplestway of including user-editable HTML content that is automatically sanitised isby using the BleachField model field:

BleachField takes the following arguments, to customise the output ofbleach. See the bleach documentation for their use:

  • allowed_tags
  • allowed_attributes
  • allowed_styles
  • strip_tags
  • strip_comments
Django

In addition to the bleach-specific arguments, the BleachField model fieldaccepts all of the normal field attributes. Behind the scenes, it is aTextField, and accepts all the same arguments as the default TextField does.

The BleachField model field makes use of the BleachField form field to doall of the work. It provides no sanitisation facilities itself. This isconsidered a bug, but a clean solution has not yet been implemented. Any pullrequests fixing this will be gratefully applied. As long as the BleachFieldmodel field is only used with BleachField form fields, there will be noproblem. If this is not the case, sanitised HTML can not be guaranteed.

In your forms

A BleachField form field is provided. This field sanitises HTML input fromthe user, and presents safe, clean HTML to your Django application. This iswhere most of the work is done.

In your templates

If you have a piece of content from somewhere that needs to be printed in atemplate, you can use the bleach filter:

If filter has no arguments it uses default settings defined in yourapplication settings. You can override allowed tags by specifying themas a parameter to the filter:

There is also bleach_linkify which uses the linkify function of bleachwhich converts URL-like strings in an HTML fragment to links

This function converts strings that look like URLs, domain names and emailaddresses in text that may be an HTML fragment to links, while preserving:

Django mozilla developer
  1. links already in the string
  2. urls found in attributes
  3. email addresses

Release historyRelease notifications | RSS feed

0.6.1

0.6.0

Django Mozilla Oidc

0.5.3

0.5.2

0.5.1

0.5.0

0.4.1

0.4.0

0.3.0

0.2.1

What Is Django Web Framework

0.2.0

0.1.5

0.1.4

0.1.3

0.1.2

0.1.1

0.1.0

MozillaDjango Mozilla

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-bleach, version 0.6.1
Filename, sizeFile typePython versionUpload dateHashes
Filename, size django_bleach-0.6.1-py2.py3-none-any.whl (14.2 kB) File type Wheel Python version py2.py3 Upload dateHashes
Filename, size django-bleach-0.6.1.tar.gz (20.2 kB) File type Source Python version None Upload dateHashes
Close

Hashes for django_bleach-0.6.1-py2.py3-none-any.whl

Hashes for django_bleach-0.6.1-py2.py3-none-any.whl
AlgorithmHash digest
SHA25659de95cd98f924992313821ab7f94cd64a03aa900ca980bd3b062d8aef1a7954
MD59dc4447e6bd6035767c2864f5685ac9c
BLAKE2-256dfcf2bf277fb6e3ca840ff6ca0c0e856bc4dd4a20e3dde31777a8f0f3c2f5f98
Close

Hashes for django-bleach-0.6.1.tar.gz

Django-mozilla-product-details

Hashes for django-bleach-0.6.1.tar.gz
AlgorithmHash digest
SHA256674709c26040618aff0741ce8261fd151e5ead405bd50568c2034662d69daac3
MD54f6f5300af49e284fe40fd76eef6b1c3
BLAKE2-256fe7e930decd45f50d7a8b4c97948442f4d0e4f8f6eea344b2b4541e836af3ae0