Home > database >  how to make the captcha have a bootstrap class?
how to make the captcha have a bootstrap class?

Time:05-21

I have a problem with the captcha, I'm using the ¨Django Simple Captcha¨ the problem is that it doesn't let me place a bootstrap class so that the input has a better appearance.

I tried to:

  • I Put widget_tweaks in that input, but it does not send the data correctly and marks errors

html

<label >Captcha</label>
{% render_field form.captcha  %}
  • From forms I placed a class inside the widget, but it doesn't work

forms.py

class RegisterForm(UserCreationForm):
   captcha=CaptchaField(widget=forms.TextInput(attrs={'class': 'form-control'}))
  • I took the input id and edit it in my style.css but the bootstrap class is not visible either

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;
   }

Any ideas for that input to have the bootstrap class?

CodePudding user response:

I haven't verified this, but you might try:

from captcha.fields import CaptchaField, CaptchaTextInput

class RegisterForm(UserCreationForm):
   captcha=CaptchaField(widget=CaptchaTextInput(attrs={'class': 'form-control'}))

Not sure if widget_tweaks plays nicely with MultiValueFields, but you could also try in your templates.

{% render_field form.captcha class ="form-control" %}

(Note the = rather than =)

Or, again using widget_tweaks

{{ form.captcha|add_class:"form-control" }}
  • Related