Tiny_mce + comments in Django = problem
I written a small comments app.
Part of forms.py:class TinyCommentForm(CommentSecurityForm):
comment = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
Part of models.py:
class TinyComment(BaseCommentAbstractModel):
comment = tinymce_models.HTMLField()
Part of template which using TinyCommentForm:
{% if user.is_authenticated %}
{% get_comment_form for object as form %}
<form action="{% comment_form_target %}" method="POST">
{{ form.comment }}
{{ form.content_type }}
{{ form.object_pk }}
{{ form.timestamp }}
{{ form.security_hash }}
<input type="submit" name="post" class="submit-post" value="Add" />
</form>
{%endif%}
Here I can adding and saving comments, but only without tinymce editor and that is working fine.
If I add to my comment form in template field: {{form.media}}
tinymce editor show up, but if I write something there, my POST form seems to be without content, saying that I need to write something to it.
Giving {{form.media}}
to <HEAD>
sector does not working even if I render through my view the TinyCommentForm as 'form' to this template.
So i tried to import JS more manually and I add to <HEAD>
section(using Django 1.3):
<script type="text/javascript" src="{{STATIC_URL}}js/tiny_mce/tiny_mce.js"></script>
Then I check that the src link and it is correct.
So next I add second line there:
<script type="text/javascript" src="{% url tinymce-js "NAME" %}"></script>
Then I create NAME/tinymce_textareas.js
with JS code and add containing this folder to TEMPLATE_DIR开发者_如何学运维S. MY urls including tiny_mce urls. But still without results.
Does somebody could illumine me a little?
Got it working good. Answer:
{% if user.is_authenticated %}
{% get_comment_form for object as form %}
<form action="{% comment_form_target %}" method="POST">
{{ form.media }} <!-- This is needed -->
{{ form.comment }}
{{ form.content_type }}
{{ form.object_pk }}
{{ form.timestamp }}
{{ form.security_hash }}
<input type="submit" name="post" class="submit-post" value="Add" />
</form>
{%endif%}
And any JS in section was needless. But the devil lives in my forms.py which should looks like this:
class TinyCommentForm(CommentSecurityForm):
comment = forms.CharField(widget=forms.Texarea)
And now everythigng works properly.
Edit: The reason of why my comment form need to using widget=forms.Texarea
is, i think, that my texareas.js has mode : "textareas"
. If I am wrong please correct me.
精彩评论