Form field widget

class djangocodemirror.widgets.CodeMirrorAdminWidget(*args, **kwargs)[source]

Bases: djangocodemirror.widgets.CodeMirrorWidget

CodeMirror widget suited for usage in models admins.

Act like CodeMirrorWidget but allways embed Codemirror Javascript config.

class djangocodemirror.widgets.CodeMirrorWidget(*args, **kwargs)[source]

Bases: django.forms.widgets.Textarea

Widget to add a CodeMirror or DjangoCodeMirror instance on a textarea Take the same arguments than forms.Textarea and accepts one suplementary optionnal arguments :

  • config_name (string) – A Codemirror config name available in settings.CODEMIRROR_SETTINGS. Default is empty.
  • embed_config (bool) – If True will add Codemirror Javascript config just below the input. Default is False.

string – For given config name.


Shortcut to get Codemirror parameters.

Returns:CodeMirror parameters.
Return type:dict

Build CodeMirror HTML script tag which contains CodeMirror init.

Parameters:final_attrs (dict) – Widget attributes that must contains the id attribute.
Returns:HTML for field CodeMirror instance.
Return type:string

Return CodeMirror HTML template from CodeMirrorWidget.codemirror_field_js.

Returns:HTML template string.
Return type:string

Initialize a manifest instance

Parameters:name (string) – Config name to register.
Returns:A manifest instance where config (from config_name attribute) is registred.
Return type:CodeMirrorManifest

Adds necessary files (Js/CSS) to the widget’s medias.

Returns:Media object with all assets from registered config.
Return type:django.forms.Media
render(name, value, attrs=None)[source]

Render widget HTML

  • name (string) – Field input name.
  • value (string) – Field input value.
Keyword Arguments:

attrs (dict) – Optional field widget attributes. Default to None.


Widget HTML representation.

Return type: