Skip to content
Django's textarea like widget for using CodeMirror on textarea
Find file
Latest commit e5ec699 Mar 4, 2016 @lambdalisue Merge pull request #21 from samluescher/master
Add the ability to load custom CSS
Failed to load latest commit information.
codemirror Add the ability to load custom CSS Mar 3, 2016
.gitignore small cleanup Sep 24, 2011


Django form widget library for using CodeMirror on Textarea


sudo pip install django-codemirror-widget


sudo pip install git+git://

How to Use

  1. First, you need to specified CODEMIRROR_PATH on CODEMIRROR_PATH is the URI of CodeMirror directory like CODEMIRROR_PATH = r"javascript/codemirror". If you don't specify it, it defaults to 'codemirror'. CodeMirror should be put there.

  2. Use codemirror.CodeMirrorTextarea widget for target Textarea like below:

    from django import forms
    from codemirror import CodeMirrorTextarea
    codemirror_widget = CodeMirrorTextarea(mode="python", theme="cobalt", config={ 'fixedGutter': True })
    document = forms.TextField(widget=codemirror_widget)


the URI of CodeMirror directory (your CodeMirror installation should live in {{ STATIC_URL }}/{{ CODEMIRROR_PATH }})
the default mode which may be a string or configuration map (DEFAULT: 'javascript')
the default theme applied (DEFAULT: 'default')
base mapping for the rest of the CodeMirror options (DEFAULT: { 'lineNumbers': True })
A format string interpolated with the form field name to name a global JS variable that will hold the CodeMirror editor object. For example with CODEMIRROR_JS_VAR_FORMAT = "%s_editor" and a field named 'code', the JS variable name would be 'code_editor'. If CODEMIRROR_JS_VAR_FORMAT is None, no global variable is created (DEFAULT: None)
Something went wrong with that request. Please try again.