Sunday, 11 August 2013

Using Bootstrap wysiwyg text editor in Django Form

Using Bootstrap wysiwyg text editor in Django Form

I am using Django and Bootrap 2.32. I want to include this
wysiwyg-bootrap-themed text editor:
http://mindmup.github.io/bootstrap-wysiwyg/. The usage of this editor is
fairly simple, including
$('#editor').wysiwyg();
in the JS-declaration will render each
<div class=editor></div>
into a beatiful wysiwyg text-editor.
Now the problem: I want to include this editor into one of my django form
field. I have the single form:
class Article_Form(ModelForm):
Article_text = CharField(widget=Textarea(attrs = {'id' : 'editor'}))
class Meta:
model= Article
, whereas the Article model includes one simple CharField . Is there any
chance, to get the editor work inside the Article_text form-field? With
the above-mentioned widget, the created textarea cannot be controlled by
the wysiwyg-editor-control buttons. Wrapping the form-template-tag like
this
<div id="editor">
{{ Article_Form.Article_text }}
</div>
doesn't work either. The problem thus is that Django creates a textarea,
wheras the editor would need a <div> to render correctly. Do you guys have
any idea how to get this to work (without refering to django-wysiwyg).
Thanks!

No comments:

Post a Comment