Flask blog post extensive controls - How to control text formating, ability to add links, pictures etc
What I needed was a WYSIWYG (What You See Is What You Get) editor. There are many freely available with popular ones being TinyMCE, Summernote, CKEditor and others.
Your current code requires few modifications. It is not that hard to integrate it with your code. You specify the required libraries and the initialization code.
Typically you have a content
field of type textarea
which will require a class
attribute as specified for the library (for Summernote say class="summernoteClass"
) such that the textarea
element can be targeted by the library's javascript code.
Then you simply store this content to the database as before. Note that this may require cleaning the content in case the user types any malicious <script>
s (if so I recommend the bleach
python module and then bleach.clean(str)
).
Finally to display the html back (and not the html entities) using Jinja2 template framework you can do so by simply appending |safe
in the html code, like so: <p class="article-content">{{ post.content | safe }}</p>
. Maybe this will help others.