使用引导程序创建包含许多行和列的窗体



>我有一个django模板,我希望它呈现一个模型形式,但具有不同的列和行。更具体地说,我希望它们位于三列的网格中,最后一行将具有剩余的(如果有的话)。我的模板正在渲染(它有点大,所以我使用了小提琴)以下代码。但是当我看到不同的行时,我的表单 stil 有一列。我错过了什么吗?

(我也必须在这里输入代码吗?

<div id="personal-data">
    <form class="form-horizontal" action="/customer/edit/1/" method="post" enctype="multipart/form-data">
        <input type="hidden" value="KTN76otstgqNoyE7Whzn6L9TAC2jvR9u" name="csrfmiddlewaretoken"></input>
        <legend> Name </legend>
        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_first_name">
                        First name
                    </label>
                    <div id="form-first_name">
                        <input id="id_first_name" class="form-control" type="text" value="Name" name="first_name" maxlength="150"></input>
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_last_name">
                        Last name
                    </label>   
                    <div id="form-last_name">
                        <input id="id_last_name" class="form-control" type="text" value="Name" name="last_name" maxlength="200"></input>
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_email">
                        Email
                    </label>
                    <div id="form-email">
                        <input id="id_email" class="form-control" type="text" name="email" maxlength="200"></input>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_telephone">
                        Telephone
                    </label>
                    <div id="form-telephone">
                        <input id="id_telephone" class="form-control" type="text" value="(664) 654-6545" placeholder="(XXX) XXX-XXXX" name="telephone" maxlength="14" autocomplete="off"></input>
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_mobile">
                        Mobile
                    </label>
                    <div id="form-mobile">
                        <input id="id_mobile" class="form-control" type="text" value="9999999999" name="mobile" maxlength="25"></input>
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_street">
                        Street
                    </label>
                    <div id="form-street">
                        <input id="id_street" class="form-control" type="text" name="street" maxlength="255"></input>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_region">
                        Region
                    </label>
                    <div id="form-region">
                        <input id="id_region" class="form-control" type="text" name="region" maxlength="130"></input>
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_state">
                        State
                    </label>
                    <div id="form-state">
                        <input id="id_state" class="form-control" type="text" name="state" maxlength="70"></input>
                   </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_city">
                        City
                    </label>
                    <div id="form-city">
                        <input id="id_city" class="form-control" type="text" name="city" maxlength="120"></input>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_neighbourhood">
                        Neighbourhood
                    </label>
                    <div id="form-neighbourhood">
                        <input id="id_neighbourhood" class="form-control" type="text" name="neighbourhood" maxlength="160"></input>
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_postal_code">
                        Postal code
                    </label>
                    <div id="form-postal_code">
                        <input id="id_postal_code" class="form-control" type="text" name="postal_code" maxlength="20"></input>
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_country">
                        Country
                    </label>
                    <div id="form-country">
                        <input id="id_country" class="form-control" type="text" name="country" maxlength="100"></input>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="id_file">
                        Picture
                    </label>
                    <div id="form-file">

                          Currently: 
                    <a href="/media/pictures/picture_1.jpg"> … </a>
                    <input id="file-clear_id" type="checkbox" name="file-clear"></input>
                        <label for="file-clear_id">
                            Clear
                        </label>
                        <br></br>
                        Change: 
                        <input id="id_file" type="file" name="file"></input>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <button class="btn form-control" type="submit"> … </button>
        </div>
    </form>
</div>

我不想在这里放这么大的代码,但它说如果我添加一个小提琴手链接,它也需要代码。

编辑:很抱歉忘了提到表单被包装在带有 .container 类的div 中。如果我将表单类更改为 .form-inline,我仍然没有得到我想要的结果,但我的表单似乎超出了"容器"的范围

你的小提琴不包括 Bootstrap。

你可以改用 Bootply(它包括 Bootstrap 和 jQuery): http://bootply.com/89310

另外,您的HTML标记有点偏离...

HTML输入应该像这样关闭。

<input id="id_country" class="form-control" type="text" name="country" maxlength="100"/>

不是这个..

<input id="id_country" class="form-control" type="text" name="country" maxlength="100"></input>

最新更新