Basic Usage ============ Installation ------------- .. code-block:: bash $ pip install flask-ckeditor Initialization -------------- This extension needs to be initialized in the usual way before it can be used: .. code-block:: python from flask_ckeditor import CKEditor app = Flask(__name__) ckeditor = CKEditor(app) This extension also supports the Flask application factory pattern by allowing you to create a CKEditor object and then separately initialize it for an app: .. code-block:: python from flask_ckeditor import CKEditor ckeditor = CKEditor() def create_app(): app = Flask(__name__) ... ckeditor.init_app(app) ... return app Include CKEditor Resources -------------------------- In the template in which you want to put a CKEditor textarea, call ``ckeditor.load()`` in ```` or before ````: .. code-block:: jinja ... {{ ckeditor.load() }} By default, it will load the CKEditor resources from CND (cdn.ckeditor.com), you can set ``CKEDITOR_SERVE_LOCAL`` to True to use built-in resources. You can use ``custom_url`` to load your custom CKEditor build: .. code-block:: jinja {{ ckeditor.load(custom_url=url_for('static', filename='ckeditor/ckeditor.js')) }} CKEditor provides five types of preset (see `comparison table `_ for the differences): - ``basic`` - ``standard`` (default value) - ``full`` - ``standard-all`` (only available from CDN) - ``full-all`` (only available from CDN) You can use `pkg_type` parameter or ``CKEDITOR_PKG_TYPE`` configuration variable to set the package type. For example: .. code-block:: jinja {{ ckeditor.load(pkg_type="basic") }} Or: .. code-block:: python app = Flask(__name__) app.config['CKEDITOR_PKG_TYPE'] = 'basic' ckeditor = CKEditor(app) This method is just a helper to generate `` Create a CKEditor Textarea --------------------------- It's quite simple, just call ``ckeditor.create()`` in the template: .. code-block:: jinja
{{ ckeditor.create() }}
You can use ``value`` parameter to pass preset value (i.e. ``ckeditor.create(value='blah...blah...')``. Get the Data ------------ Since the CKEditor textarea is just a normal ``