Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Django widgets for replacing textareas with CodeMirror2, an in-browser code editor

Project description

Django widgets for replacing textareas with CodeMirror, an in-browser code editor. Tested on Django 1.6+, support Python 2.7 and Python 3.4+.


  1. run pip install django-codemirror2
  2. Add codemirror2 to INSTALLED_APPS
  3. Collect static files: python collectstatic

To use django-codemirror2 directly from git, you need to initialize the Codemirror submodule by running git submodule init && git submodule update.


from django import forms
from codemirror2.widgets import CodeMirrorEditor

class TestForm(forms.Form):
    css = forms.Charfield(widget=CodeMirrorEditor(options={'mode': 'css'}))

The options argument will be passed as JSON to CodeMirror.fromTextArea, see for possible values. Do not pass user-controlled data as options, as this can lead to an XSS vulnerability.

If you want to use a mode that depends on other modes, for example htmlmixed, you need to load the dependencies, too, by passing the modes parameter:

html = forms.Charfield(widget=CodeMirrorEditor(modes=['css', 'xml', 'javascript', 'htmlmixed'],
            options={'mode': 'htmlmixed'}))

If you want to customize the Javascript used to initialize the CodeMirror editor, use script_template:

foo = forms.Charfield(widget=CodeMirrorEditor(options={'mode': 'xml'},

You can base your script template on the included template codemirror_script.html.

Example app

There is a simple example app included. To run it:

  1. run tox -e devenv
  2. run ./
  3. visit http://localhost:8000/admin/testapp/ in your browser.

Project details

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django-codemirror2-0.2.tar.gz (887.3 kB) Copy SHA256 hash SHA256 Source None Feb 3, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page