Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.


django-pygments is unavailable in PyPM, because there aren't any builds for it in the package repositories. Click the linked icons to find out why.

 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)

django-pygments is a Django app that provides a template tag and 2 filters for doing syntax highlighting with Pygments ( http://pygments.org/ ).

Dependencies: - pygments

Installation: - add django_pygments to your project directory and to INSTALLED_APPS in your settings.py - if you want to see the integrated demo page, add a urls.py entry and copy/link the media files in the proper dir

Usage: - enclose your code snippet in a pre tag with the non-standard "lang" attribute set to a supported language like this:

System Message: ERROR/3 (<string>, line 12)

Unexpected indentation.
<pre lang="python">....</pre>

System Message: WARNING/2 (<string>, line 13)

Block quote ends without a blank line; unexpected unindent.
  • see the view and demo template for examples on how to use the "pygmentify" and "pygmentify_inline" filters (the later is rather useful for RSS feeds) or the "pygment" tag
  • While using the "pygment" template tag, you can pass keyword arguments that you would pass to Pygments HtmlFormatter class constructor by passing them as with keyword arguments along with the pygment tag. Look at demo template for examples. There is one caveat with this feature still. You can only pass Python values as argument values (like Strings wrapped within quotes or True or False boolean values, etc.). It doesn't support Django template/context variables as arguments yet.

Notes: - the custom HTML formatter class displays each line as an ordered list element, thus implementing line numbering without interfering with copy/pasting - to see a list of supported languages, look at the "lexer_names" variable in utils.py

The project's site is here: http://od-eon.com/labs/django-pygments/ For technical support use the github issue tracker or contact us at developers@od-eon.com

Subscribe to package updates

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.