如何让验证码有一个bootstrap class?
how to make the captcha have a bootstrap class?
我的验证码有问题,我正在使用“Django 简单验证码”,问题是它不允许我放置 bootstrap class 以便输入更好看。
我试过:
- 我把 widget_tweaks 放在那个输入中,但它没有正确发送数据并标记错误
html
<label class="form-label">Captcha</label>
{% render_field form.captcha class="form-control" %}
- 我在表单中放置了一个 class 小部件,但它不起作用
forms.py
class RegisterForm(UserCreationForm):
captcha=CaptchaField(widget=forms.TextInput(attrs={'class': 'form-control'}))
- 我获取了输入 ID 并在我的 style.css 中对其进行了编辑,但是 bootstrap class 也不可见
style.css
#id_captcha_1{
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
}
有什么想法可以使输入具有 bootstrap class?
我还没有验证过,但你可以试试:
from captcha.fields import CaptchaField, CaptchaTextInput
class RegisterForm(UserCreationForm):
captcha=CaptchaField(widget=CaptchaTextInput(attrs={'class': 'form-control'}))
不确定 widget_tweaks 是否与 MultiValueFields 配合得很好,但您也可以在模板中尝试。
{% render_field form.captcha class+="form-control" %}
(注意 += 而不是 =)
或者,再次使用 widget_tweaks
{{ form.captcha|add_class:"form-control" }}
我的验证码有问题,我正在使用“Django 简单验证码”,问题是它不允许我放置 bootstrap class 以便输入更好看。
我试过:
- 我把 widget_tweaks 放在那个输入中,但它没有正确发送数据并标记错误
html
<label class="form-label">Captcha</label>
{% render_field form.captcha class="form-control" %}
- 我在表单中放置了一个 class 小部件,但它不起作用
forms.py
class RegisterForm(UserCreationForm):
captcha=CaptchaField(widget=forms.TextInput(attrs={'class': 'form-control'}))
- 我获取了输入 ID 并在我的 style.css 中对其进行了编辑,但是 bootstrap class 也不可见
style.css
#id_captcha_1{
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
}
有什么想法可以使输入具有 bootstrap class?
我还没有验证过,但你可以试试:
from captcha.fields import CaptchaField, CaptchaTextInput
class RegisterForm(UserCreationForm):
captcha=CaptchaField(widget=CaptchaTextInput(attrs={'class': 'form-control'}))
不确定 widget_tweaks 是否与 MultiValueFields 配合得很好,但您也可以在模板中尝试。
{% render_field form.captcha class+="form-control" %}
(注意 += 而不是 =)
或者,再次使用 widget_tweaks
{{ form.captcha|add_class:"form-control" }}