[英]How can I show a specific django field in html?
So I want to do what the title says and I don't know how since I'm new at this. 所以我想按标题所说做,但我不知道怎么做,因为我是新来的。
<p>{{ form.description }}</p>
That's the way I show information from different models in a listing using 这就是我使用列表显示来自不同模型的信息的方式
{% for form in forms %}
But I want to show the description of an specific object. 但是我想显示一个特定对象的描述。
Thanks in advance. 提前致谢。
<form method="post" novalidate>{% csrf_token %}
{{ form.non_field_errors }}
{% for hidden_field in form.hidden_fields %}
{{ hidden_field.errors }}
{{ hidden_field }}
{% endfor %}
<table border="1">
{% for field in form.visible_fields %}
<tr>
<th>{{ field.label_tag }}</th>
<td>
{{ field.errors }}
{{ field }}
{{ field.help_text }}
</td>
</tr>
{% endfor %}
Look this article: [link][1] https://simpleisbetterthancomplex.com/article/2017/08/19/how-to-render-django-form-manually.html 看这篇文章:[link] [1] https://simpleisbetterthancomplex.com/article/2017/08/19/how-to-render-django-form-manually.html
Usually django templates will be filled with the data rendered from the django views as dictionary and these will be callable in templates using django template tags "{{tag_name}}" 通常,django模板将用django视图中呈现的数据作为字典填充,并且可以使用django模板标签“ {{tag_name}}”在模板中调用这些数据。
Here you will be rendering all the forms as a list inside the dictionary so you can show each form by looping it. 在这里,您将所有表单呈现为字典内的列表,以便您可以循环显示每个表单。
{% for form in forms %}
{{form.description}}
{% endfor %}
Like this, you can show each form's data. 这样,您可以显示每个表单的数据。 Instead of this if you only want to show a specific form's data then the proper way is to render the view with the specific form's data and show data in template using the template tag {{form.description}}
如果您只想显示特定表单的数据,则代替此方法,正确的方法是使用特定表单的数据呈现视图,并使用模板标签{{form.description}}在模板中显示数据
Check the django documentation : https://docs.djangoproject.com/en/2.1/topics/templates/ 检查django文档: https : //docs.djangoproject.com/en/2.1/topics/templates/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.