For me this is weird, maybe it isn't and I'm missing something obvious:
forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class formRegistro(UserCreationForm):
class Meta:
model = User
fields = ("first_name", "last_name", "email", "username", "password1", "password2")
widgets = {
'first_name': forms.TextInput(attrs={'class':'form-control'}),
'last_name': forms.TextInput(attrs={'class':'form-control'}),
'email': forms.TextInput(attrs={'class':'form-control'}),
'username': forms.TextInput(attrs={'class':'form-control'}),
'password1': forms.PasswordInput(attrs={'class':'form-control'}),
'password2': forms.PasswordInput(attrs={'class':'form-control'})
}
views.py
def registro(request):
template = "perfiles/registro.html"
form = formRegistro()
context = {'form' : form}
return render(request, template, context)
html registro.html
<form class="form-horizontal" action="{% url 'perfiles:registro' %}" method="post">
{% csrf_token %}
<fieldset>
{{form}}
</fieldset>
<input type="submit" value="Submit">
</form>
It looks fine to me, I'm just rendering a form. All I want is to add "form-control" to the input's classes. What is weird is that it only adds "form-control" to the fields "first_name", "last_name" and "email_address". ?ยก No form-control-class for the inputs "username", "password1" and "password2".
Here is the rendered html: