登録フォームがあり、私はDjango登録を使用しています。今、各フィールドにcssクラスを追加する必要があります。また、検証エラーがある場合、cssクラスはエラーのあるフィールドに対して異なる必要があります。どうすればこれを達成できますか? HTMLテンプレートで要素のクラス属性を変更する - Djangoフォーム
class RegistrationForm(forms.Form):
"""
Form for registering a new user account.
Validates that the requested username is not already in use, and
requires the password to be entered twice to catch typos.
Subclasses should feel free to add any additional validation they
need, but should avoid defining a ``save()`` method -- the actual
saving of collected user data is delegated to the active
registration backend.
"""
error_css_class = 'error'
required_css_class='wanted'
email = forms.EmailField(widget=forms.TextInput(attrs=dict(maxlength=75)),
label=_("Email address"))
password1 = forms.CharField(widget=forms.PasswordInput(render_value=False),
label=_("Password"))
password2 = forms.CharField(widget=forms.PasswordInput(render_value=False),
label=_("Password (again)"))
、私は
<div class="row">
<label for="id_email"><span>*</span> Email Address:</label>
{{ form.email }}
</div>
をしています注は結局、私は私が
{{form.email|add_class:"blink"|add_error_class:"error"}}
+1。人々はカスケーディングスタイルシートの*カスケード*部分を忘れているようです。 –
両方の属性を追加しましたが、機能しません。フィールドは、email = forms.EmailField(widget = forms.TextInput(attrs = dict(maxlength = 75))、 label = _( "メールアドレス")) – John
のように定義されています。 、テンプレート、および出力を表示します。 – Alasdair