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
pip install django-codemirror2
Add codemirror2 to INSTALLED_APPS
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
File details
Details for the file django-codemirror2-0.0.3.tar.gz
.
File metadata
- Download URL: django-codemirror2-0.0.3.tar.gz
- Upload date:
- Size: 408.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af9cb64d9a9a19c2cb3ec152c334200375aa6bd8e5589d57bc194d57ef7614fb |
|
MD5 | b91e7c07064c13da51df9ed0e751656f |
|
BLAKE2b-256 | 82f9217c5585e278962e5b42b2d8e0e3b743dda997ca3381b849b4105737d287 |