Skip to main content

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+.

https://travis-ci.org/sk1p/django-codemirror2.svg?branch=master

Installing

  1. run pip install django-codemirror2

  2. Add codemirror2 to INSTALLED_APPS

  3. Collect static files: python manage.py collectstatic

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

Usage

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 http://codemirror.net/manual.html#config 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'},
            script_template='some/template.html'))

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 ./run_example_server.sh

  3. visit http://localhost:8000/admin/testapp/ in your browser.

Release files for django-codemirror2 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-codemirror2 0.2
File Size Uploaded
django-codemirror2-0.2.tar.gz 887.3 kB Details

Release files / django-codemirror2-0.2.tar.gz

Download URL django-codemirror2-0.2.tar.gz
Size 887.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5ab23891d410206ee36e1b8f834b17ff2eab7a5b82238b22eaa82e26c92c5ea5
BLAKE2b-256 checksum
How to use checksums
9d3c1672addfec7976acff4fe4e93d6a3a45d2757e434933aac9d46bca37c284
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page