Skip to main content

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

Project description

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

Installing

  1. pip install django-codemirror2

  2. Add codemirror2 to INSTALLED_APPS

  3. Collect static files: python manage.py collectstatic

If you just want to see it in action, see the almost-ready-to-run project in examples.

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. 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'))

Project details


Download files

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

Source Distribution

django-codemirror2-0.1.tar.gz (713.6 kB view details)

Uploaded Source

File details

Details for the file django-codemirror2-0.1.tar.gz.

File metadata

File hashes

Hashes for django-codemirror2-0.1.tar.gz
Algorithm Hash digest
SHA256 f57ca9e6f2c180d82f7e07e66ec7c8ec8255d4b9c1e6cc194fa2d89ef56c08c7
MD5 19a86d91785fd19e8fe8f8cd3836432f
BLAKE2b-256 1a5bf393d9f2736d2a083d8ff478365609e95e27d2f33e39f7a758d6e6361ba2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page