Django-ace-editor is an implementation of the ajax.org Ace editor as a form widget.
::
from django import forms
from django_ace import AceWidget
class EditorForm(forms.Form):
text = forms.CharField(widget=AceWidget)
Syntax highlighting and static analysis can be enabled by specifying the language::
class EditorForm(forms.Form):
text = forms.CharField(widget=AceWidget(mode='css'))
Themes are also supported::
class EditorForm(forms.Form):
text = forms.CharField(widget=AceWidget(mode='css', theme='twilight'))
All options, and their default values, are::
class EditorForm(forms.Form):
text = forms.CharField(widget=AceWidget(
mode=None, # try for example "python"
theme=None, # try for example "twilight"
wordwrap=False,
width="500px",
height="300px",
minlines=None,
maxlines=None,
showprintmargin=True,
showinvisibles=False,
usesofttabs=True,
tabsize=None,
fontsize=None,
toolbar=True,
readonly=False,
showgutter=True, # To hide/show line numbers
behaviours=True, # To disable auto-append of quote when quotes are entered
))
Install using pip::
pip install django_ace
Update INSTALLED_APPS
::
INSTALLED_APPS = ( # ... 'django_ace', )
There's an example project included in the source, to try it do::
cd example/
virtualenv .env
. .env/bin/activate
pip install -e ..
./manage.py makemigrations app
./manage.py migrate
./manage.py runserver
Then browser to http://localhost:8000
.
width="100%"
without breaking the layout.JavaScriptCatalog
.showgutters
to hide line numbers.behaviours
to avoid auto-insert of quotes.readonly
.toolbar
.fontsize
.tabsize
.>1.11,<=2.1
minLines
, maxLines
, showinvisibles
, usesofttabs
.