django重用表单模板来显示数据?

时间:2017-11-30 10:07:31

标签: django django-forms django-templates

所以我有十几种用户输入的表单,我已经创建了一段时间(不得不手动操作,因为表单必须以某种方式查看)。例如:

<div class="">
    <h4 class="row">Provide data for Installation Report</h4>
    <form action="" method="POST">
        {% csrf_token %}
        <div>
            <p class="row">Onsite Installation (Completed by Installer)<br> Installer must complete one “Service Provider” Section for each unit installed</p>
            <div class="row z-depth-2 input-grouping">
                <div class="col s12 m12 l6 ">
                    <input class="datepicker" id="id_installationDate" name="installationDate" type="text" required />
                    <label for="id_installationDate">Date of Installation</label>
                </div>
                <div class="col s12 m12 l6 ">
                    <input id="id_deliveryOrder" maxlength="255" name="deliveryOrder" type="text" />
                    <label for="id_deliveryOrder">Delivery Order</label>
                </div>
            </div>
            <div class="row z-depth-2 input-grouping">
                <div class="col s12 m12 l6 ">
                    <input id="id_unitSerialNumber" maxlength="255" name="unitSerialNumber" type="text" required />
                    <label for="id_unitSerialNumber">Unit Serial Number</label>
                </div>
                <div class="col s12 m12 l6">
                    <input id="id_unitHours" name="unitHours" step="0.01" type="number" required />
                    <label for="id_unitHours">Unit Hours</label>
                </div>
            </div>
And so on ...

例如,此表单将数据保存到InstallationReport模型。

现在我需要在某处显示InstallationReport对象。如果我不必在上面的表单中复制粘贴html(然后绑定数据),那就太棒了。相反,如果我可以使用表单本身来显示对象,那对我来说就更容易了。

有没有办法让我这样做而不会有太多麻烦?

0 个答案:

没有答案