Django form widget library for using CodeMirror on textarea
Project description
Django form widget library for using CodeMirror on Textarea.
Installation
pip install django-codemirror-widget
Usage
First, you need to specified CODEMIRROR_PATH on settings.py. 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.
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)
Settings
Use the followings in your settings.py.
CODEMIRROR_PATH
The URI of CodeMirror directory (your CodeMirror installation should live in {{ STATIC_URL }}/{{ CODEMIRROR_PATH }})
CODEMIRROR_MODE
The default mode which may be a string or configuration map (DEFAULT: 'javascript')
CODEMIRROR_THEME
The default theme applied (DEFAULT: 'default')
CODEMIRROR_CONFIG
Base mapping for the rest of the CodeMirror options (DEFAULT: { 'lineNumbers': True })
CODEMIRROR_JS_VAR_FORMAT
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-codemirror-widget-0.4.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d24ef00c61677171117e7c8d49d8281cc08bd3fd6be6a4ea584def08edcb9b8 |
|
MD5 | ab64c6a33d317d9f1a6211d65c575cb7 |
|
BLAKE2b-256 | d39b7038890841690f1d8feb1e3b85ac32e7b87d4f3c53b5fb1ec0c4ef4b5b75 |