from django import forms
from django.utils.translation import ugettext_lazy,ugettext as _
from django.contrib.auth.models import User
from .models import Page, HomeBanner, ColorBox,IconBox,HomeVideo
from django.db.models import Q
class PageForm(forms.ModelForm):
title = forms.CharField(widget=forms.TextInput(attrs={'label':ugettext_lazy('Title'),'class':'form-control'}))
title_small = forms.CharField(widget=forms.TextInput(attrs={'label':_('Title Small'),'class':'form-control'}),required=False)
status = forms.ChoiceField(choices=(
('draft', _('draft')),
('published', _('published')),
('deleted', _('deleted')),
), widget=forms.Select(attrs={'label':_('Status'),'class':'form-control'}),required=True)
他们正在进行选择但不在标签定义中工作。
出了什么问题?答案 0 :(得分:1)
您应该将label
作为参数传递给表单,而不是作为窗口小部件属性。
class PageForm(forms.ModelForm):
title = forms.CharField(label=ugettext_lazy('Title'),
widget=forms.TextInput(attrs={'class':'form-control'}),
)
...