문제

(using django.contrib.comments)

When placing :

{% load comments %}
{% render_comment_form for event %}

into the template. It renders a form with a: Name, email, url and comment field.

Is there a way to just have the comment field appear, and have the other fields hidden while still posting data? Or should I just recreate the form myself?

Thank you in advance for you suggestions.

도움이 되었습니까?

해결책

You can add the attribute is_hidden to a field of the comments form and give it the value True. In that case only the value of the field will be printed but I'm not sure this is what you want.

But fortunately you can modify the form yourself. The code searches for a template at the following locations:

template_search_list = [
    "comments/%s/%s/form.html" % (ctype.app_label, ctype.model),
    "comments/%s/form.html" % ctype.app_label,
    "comments/form.html"
]

You can view the current contents of form.html here and the code of the render_comments_form template tag here).

If you want to modify the form for the whole website then you can create your own version of comments/form.html but you can also create a form.htm for a particular Django app or even a particular model of a Django app. In that form template you can customize which fields are displayed and which ones are hidden.

다른 팁

just add this line in your form.html page:-

{% if field.name != "name" and field.name != "email" and field.name != "url" %}

u'll need to add it like this:-

{% if field.is_hidden %}
<div>{{ field }}</div>
{% else %}
{% if field.name != "name" and field.name != "email" and field.name != "url" %}
{% if field.errors %}{{ field.errors }}{% endif %}

...it worked for me...no need to do anythng else..i just wanted the comment box and nothin else!!!!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top