【问题标题】:There is any way to add classes to bootstrap_django form_fields?有什么方法可以将类添加到 bootstrap_django form_fields?
【发布时间】:2014-07-30 05:31:17
【问题描述】:

https://github.com/dyve/django-bootstrap3 我非常喜欢。

顺便说一句,我需要添加类来自定义我的 ui 并添加基于行为类。 我想做模板方面的。

我用那个:

{% bootstrap_form form_field FIXTHIS %}

但我不明白: - 项目太年轻了,没有那个功能 - 该功能可用,我不能 - 我在 Django 上的一般技能问题:解决问题的方法错误

这里的文档: http://django-bootstrap3.readthedocs.org/en/latest/templatetags.html#bootstrap-field

编辑: 这样做的伎俩,仍然使用 django_bootstrap。 顺便说一句,在 form.py 文件中。 这种方法是否正确,或者我应该继续尝试在模板中移动该逻辑?

class AuthorForm(forms.ModelForm):
    class Meta:
        model = Author
        fields = ['code','name','birthdate',]
        widgets = {
            'birthdate': forms.TextInput(attrs={'class': 'datepicker'}),
        }

【问题讨论】:

  • Django 的策略是:模板中的逻辑更少。所以我建议你应该在表单中保留逻辑或使用模板标签
  • 谢谢@Brandon,我看了一下。该项目的最后一次提交是在 2013 年 4 月 4 日...现在我面向 WTForm... :) 还不错。 wtforms.readthedocs.org/en/latest
  • 不客气。我仍然发现 Django Widget Tweaks 非常有用,尽管它已经有一段时间没有任何新的开发了。我不会因此而阻止您使用它。

标签: css django twitter-bootstrap class django-templates


【解决方案1】:

使用表单中的类,如下所示:

'email': TextInput(attrs={'class': 'form-control', 'placeholder': ('Type your email here')}),

【讨论】:

  • 所以你确认它不可能在模板端进行。
  • 我不确定,但最好从表单方面进行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 1970-01-01
  • 2022-11-12
  • 2021-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多