Giter Site home page Giter Site logo

jtraulle / django-codemirror2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sk1p/django-codemirror2

0.0 2.0 0.0 27 KB

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

License: MIT License

HTML 2.71% Python 94.50% Shell 2.79%

django-codemirror2's Introduction

Django widgets for replacing textareas with CodeMirror, an in-browser code editor. Tested on Django 1.6+, support Python 2.7 and Python 3.4+.

image

Installing

  1. run pip install django-codemirror2
  2. Add codemirror2 to INSTALLED_APPS
  3. Collect static files: python manage.py collectstatic

To use django-codemirror2 directly from git, you need to initialize the Codemirror submodule by running git submodule init && git submodule update.

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. Do not pass user-controlled data as options, as this can lead to an XSS vulnerability.

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

You can base your script template on the included template codemirror_script.html.

Example app

There is a simple example app included. To run it:

  1. run tox -e devenv
  2. run ./run_example_server.sh
  3. visit http://localhost:8000/admin/testapp/ in your browser.

django-codemirror2's People

Contributors

jowolf avatar sk1p avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.