Django documentation

The “django.contrib” add-ons

This document is for Django's SVN release, which can be significantly different from previous releases. Get old docs here: 0.96, 0.95.

Django aims to follow Python’s “batteries included” philosophy. It ships with a variety of extra, optional tools that solve common Web-development problems.

This code lives in django/contrib in the Django distribution. This document gives a rundown of the packages in contrib, along with any dependencies those packages have.

Note

For most of these add-ons — specifically, the add-ons that include either models or template tags — you’ll need to add the package name (e.g., 'django.contrib.admin') to your INSTALLED_APPS setting and re-run manage.py syncdb.

admin

The automatic Django administrative interface. For more information, see Tutorial 2.

Requires the auth and contenttypes contrib packages to be installed.

auth

Django’s authentication framework.

See the authentication documentation.

comments

A simple yet flexible comments system. This is not yet documented.

contenttypes

A light framework for hooking into “types” of content, where each installed Django model is a separate content type.

See the contenttypes documentation.

csrf

A middleware for preventing Cross Site Request Forgeries

See the csrf documentation.

flatpages

A framework for managing simple “flat” HTML content in a database.

See the flatpages documentation.

Requires the sites contrib package to be installed as well.

formtools

A set of high-level abstractions for Django forms (django.newforms).

django.contrib.formtools.preview

An abstraction of the following workflow:

“Display an HTML form, force a preview, then do something with the submission.”

See the form preview documentation.

humanize

A set of Django template filters useful for adding a “human touch” to data. To activate these filters, add 'django.contrib.humanize' to your INSTALLED_APPS setting. Once you’ve done that, use {% load humanize %} in a template, and you’ll have access to these filters:

apnumber

For numbers 1-9, returns the number spelled out. Otherwise, returns the number. This follows Associated Press style.

Examples:

  • 1 becomes 'one'.
  • 2 becomes 'two'.
  • 10 becomes 10.

You can pass in either an integer or a string representation of an integer.

intcomma

Converts an integer to a string containing commas every three digits.

Examples:

  • 4500 becomes '4,500'.
  • 45000 becomes '45,000'.
  • 450000 becomes '450,000'.
  • 4500000 becomes '4,500,000'.

You can pass in either an integer or a string representation of an integer.

intword

Converts a large integer to a friendly text representation. Works best for numbers over 1 million.

Examples:

  • 1000000 becomes '1.0 million'.
  • 1200000 becomes '1.2 million'.
  • 1200000000 becomes '1.2 billion'.

Values up to 1000000000000000 (one quadrillion) are supported.

You can pass in either an integer or a string representation of an integer.

ordinal

Converts an integer to its ordinal as a string.

Examples:

  • 1 becomes '1st'.
  • 2 becomes '2nd'.
  • 3 becomes '3rd'.

You can pass in either an integer or a string representation of an integer.

naturalday

New in Django development version

For dates that are the current day or within one day, return “today”, “tomorrow” or “yesterday”, as appropriate. Otherwise, format the date using the passed in format string.

Argument: Date formatting string as described in default tag now.

Examples (when ‘today’ is 17 Feb 2007):

  • 16 Feb 2007 becomes yesterday.
  • 17 Feb 2007 becomes today.
  • 18 Feb 2007 becomes tomorrow.
  • Any other day is formatted according to given argument or the DATE_FORMAT setting if no argument is given.

localflavor

A collection of various Django snippets that are useful only for a particular country or culture. For example, django.contrib.localflavor.us.forms contains a USZipCodeField that you can use to validate U.S. zip codes.

See the localflavor documentation.

markup

A collection of template filters that implement common markup languages:

In each case, the filter expects formatted markup as a string and returns a string representing the marked-up text. For example, the textile filter converts text that is marked-up in Textile format to HTML.

To activate these filters, add 'django.contrib.markup' to your INSTALLED_APPS setting. Once you’ve done that, use {% load markup %} in a template, and you’ll have access to these filters. For more documentation, read the source code in django/contrib/markup/templatetags/markup.py.

redirects

A framework for managing redirects.

See the redirects documentation.

sessions

A framework for storing data in anonymous sessions.

See the sessions documentation.

sites

A light framework that lets you operate multiple Web sites off of the same database and Django installation. It gives you hooks for associating objects to one or more sites.

See the sites documentation.

sitemaps

A framework for generating Google sitemap XML files.

See the sitemaps documentation.

syndication

A framework for generating syndication feeds, in RSS and Atom, quite easily.

See the syndication documentation.

webdesign

Helpers and utilties targeted primarily at Web designers rather than Web developers.

See the Web design helpers documentation.

Other add-ons

If you have an idea for functionality to include in contrib, let us know! Code it up, and post it to the django-users mailing list.

Questions/Feedback

If you notice errors with this documentation, please open a ticket and let us know!

Please only use the ticket tracker for criticisms and improvements on the docs. For tech support, ask in the IRC channel or post to the django-users list.