2011-05-07 45 views
0

我寫了一個小小的評論應用程序。
forms.py的部分:models.py的Tiny_mce + Django中的註釋=問題

class TinyCommentForm(CommentSecurityForm): 
    comment = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) 

部分:其中使用TinyCommentForm

class TinyComment(BaseCommentAbstractModel): 
    comment = tinymce_models.HTMLField() 

模板的一部分:

{% 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%} 

在這裏,我可以添加和保存的意見,但只有沒有tinymce編輯器,並且工作正常。

如果我在模板字段中添加我的評論表單:{{form.media}} tinymce編輯器顯示出來,但是如果我在那裏寫了一些內容,我的POST表單似乎沒有內容,說我需要寫一些東西給它。

{{form.media}}<HEAD>即使我通過我的視圖渲染TinyCommentForm作爲'form'到這個模板,扇區也不起作用。

所以我試圖更手動導入JS和我添加到<HEAD>節(使用Django 1.3):

<script type="text/javascript" src="{{STATIC_URL}}js/tiny_mce/tiny_mce.js"></script> 

然後我檢查SRC鏈接,它是正確的。

所以下次我添加第二行有:

<script type="text/javascript" src="{% url tinymce-js "NAME" %}"></script> 

然後,我創建NAME/tinymce_textareas.js與JS代碼,並添加包含此文件夾TEMPLATE_DIRS。我的網址包括tiny_mce網址。但仍然沒有結果。

有人可以照亮我一點嗎?

回答

1

得到它的工作良好。答:

{% 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%} 

而且在任何部分JS是不必要的。 但魔鬼住在我forms.py這應該是這樣的:

class TinyCommentForm(CommentSecurityForm): 
    comment = forms.CharField(widget=forms.Texarea) 

現在everythigng正常工作。

編輯:爲什麼我的評論的形式需要使用widget=forms.Texarea的原因,我認爲,我的texareas.js有mode : "textareas"。如果我錯了,請糾正我。