【问题标题】:How can I obtain horizontal data entry fields in a django template using the formset?如何使用表单集在 django 模板中获取水平数据输入字段?
【发布时间】:2012-07-03 09:24:43
【问题描述】:

我有以下模板,它生成一个带有垂直数据输入字段的表单。请指导我实现“水平”数据输入字段。

<html>
<head>
<title>BUDGET</title>
</head>
<body>
<p>BUDGET MANAGEMENTS</p>
<p>Your Account Number is : {{ account_number }}.</p> <p>You Chose {{ period }} {{month}} as period<p>   
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %} 
<form action="." method="post">{% csrf_token %}
{{ formset.management_form }}
<table>
{% for form in formset.forms %}
{{ form }}
{% endfor %}
</table>    
<input type="submit" value="Submit">
</form>
</body>
</html>

【问题讨论】:

标签: django templates formset


【解决方案1】:

参见 Django 文档中的 Displaying a form using a template。它包含如何控制表单呈现的确切指南。比如:

<table>
{% for form in formset.forms %}
    <tr>
    {% for field in form %}
       <td>
         {{ field.errors }}
         {{ field.label_tag }}: {{ field }}
       </td>
    {% endfor %}
    </tr>
{% endfor %}
</table>   

【讨论】:

    【解决方案2】:

    您可以通过 CSS 而不仅仅是表单呈现来做到这一点。您需要创建内联表单元素。 也许你可以看看Twitter Bootstrap CSS 库或类似的库。

    【讨论】:

      猜你喜欢
      • 2020-07-13
      • 2019-02-23
      • 2017-12-25
      • 2019-11-22
      • 2017-09-27
      • 2017-07-27
      • 2011-02-04
      • 2011-03-13
      • 2018-04-12
      相关资源
      最近更新 更多