【问题标题】:bootstrap styling not working with django floppyforms引导样式不适用于 django floppyforms
【发布时间】:2014-10-28 18:26:24
【问题描述】:

我正在从 Django Crispy Forms 切换到 Floppy Forms,但我想要的 Bootstrap 样式似乎丢失了;现在它看起来就像一个普通的无样式表单。

香脆

这是我使用 Crispy Forms 的 Bootstrap 模板包所拥有的:

这是生成的源代码:

<div id="div_id_sent_amount" class="form-group has-error">
        <label for="id_sent_amount" class="control-label  requiredField">How much would you like to give?
        <span class="asteriskField">*</span>
        </label>
        <div class="controls ">
        <select class="select form-control" id="id_sent_amount" name="sent_amount"><option value="" selected="selected">---------</option><option value="0.00">$0.00</option><option value="0.05">$0.05</option><option value="0.10">$0.10</option></select>
        <span id="error_1_id_sent_amount" class="help-block"><strong>This field is required.</strong></span></div>
</div>

软盘

这是我使用 Bootstrap 布局 here 使用 Floppy 得到的结果。

这是生成的源代码:

<div class="form-group error">
    <label class="col-sm-4 control-label" for="id_sent_amount">Sent amount <span class="required">*</span>:</label>

        <div class="controls col-sm-8  field-sent_amount">
            <select id="id_sent_amount" name="sent_amount">
                 <option value="" selected="selected">---------</option>
                 <option value="0.00">$0.00</option>
                 <option value="0.05">$0.05</option>
                 <option value="0.10">$0.10</option>
            </select>
            <ul class="errorlist"><li>This field is required.</li></ul>

        </div><!--- .controls -->

关于我缺少什么的任何想法?

【问题讨论】:

    标签: django twitter-bootstrap django-crispy-forms django-floppyforms


    【解决方案1】:

    floppyforms 只是提供更简单的布局和小部件控制,它不会自动启用引导样式。

    为此,您必须按照the documentation 中的详细说明做一些工作。

    总之,您必须创建这些模板:

    1. floppyforms/templates/floppyforms/layouts/bootstrap.html
    2. floppyforms/templates/floppyforms/rows/bootstrap.html
    3. floppyforms/templates/floppyforms/layouts/default.html
    4. floppyforms/templates/floppyforms/errors.html

    用引导程序特定的样式填充它们(in the documentation 提供了示例)。

    请记住,这些示例适用于旧版本的引导程序;您可能希望使用 current version of bootstrap 更新模板。

    您可以手动编辑模板以使其保持最新状态,或者使用django-floppyforms-bootstrap3,它确实如其所说 - 更新模板以兼容 bootstrap3。

    【讨论】:

    • 嗨,Burhan,我已经这样做了。我看到一些 Bootstrap 类正在应用于我的表单,例如 class="col-sm-4",但外观仍然不像以前那样。
    • 您是否忘记包含引导 css?
    • 我有 (static/bootstrap/css/bootstrap.min.css),页面的其余部分正在使用 bootstrap 进行样式设置,只是表单没有。
    • 你有一个班级field-sent_amount这是什么?它不是来自默认的引导 CSS。
    • 这是由 Floppy 的rows/bootstrap.html (django-floppyforms.readthedocs.org/en/latest/bootstrap.html) 生成的。看到它说:field-{{ field.name }}
    猜你喜欢
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 2016-07-11
    • 2021-03-27
    • 2019-03-21
    • 1970-01-01
    • 2018-06-02
    相关资源
    最近更新 更多