Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Use CodeMirror Javascript library with Flask-WTF

Project Description

Implementation of source code editor for Flask and Flask-WTF using CodeMirror Javascript library


$ pip install flask-codemirror


A simple example of how to use this module

from import form
from flask.ext.codemirror.fields import CodeMirrorField
from wtforms.fields import SubmitField

class MyForm(Form):
    source_code = CodeMirrorField(language='python', config={'lineNumbers' : 'true'})
    submit = SubmitField('Submit')

The CodeMirrorField works exactly like a TextAreaField

@app.route('/', methods = ['GET', 'POST'])
def index():
    form = MyForm()
    if form.validate_on_submit():
        text =
    return render_template('index.html', form = form)

The module needs to be initialized in the usual way and can be configured using app.config keys

from flask.ext.codemirror import CodeMirror
# mandatory
CODEMIRROR_LANGUAGES = ['python', 'html']
# optional
app = Flask(__name__)
codemirror = CodeMirror(app)

The config CODEMIRROR_LANGUAGES needs to be initialized to load JavaScript. It defined all the languages you want to edit with your fields. The config CODEMIRROR_THEME is optional and is used to style your TextArea using css from CodeMirror website. The config CODEMIRROR_ADDONS is optional and can enable many cool options see Codemirror Addons for available addons.

Finally, the template needs the support Javascript code added, by calling codemirror.include_codemirror() :

    {{ codemirror.include_codemirror() }}
    <form method="POST">
       {{ form.source_code }}
       <input type="submit" value="OK">

The Javascript classes are imported from a CDN, there are no static files that need to be served by the application.

Release History

This version
History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(8.7 kB) Copy SHA256 Hash SHA256
Wheel 2.7 Feb 28, 2016
(23.9 kB) Copy SHA256 Hash SHA256
Source None Feb 28, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting