How can I remove the text of labels in a Django generated form?
I have a form that renders well just for label text, which I don't want, and I've tried everything I can to disconnect it from my form, but it won't just ...
forms.py
class sign_up_form(forms.ModelForm):
class Meta:
model = Users
fields =['email']
widgets = {
'email': forms.EmailInput(attrs={
'id': 'email',
'class': 'form-control input-lg emailAddress',
'name': 'email',
'placeholder': 'Enter a valid email'})}
I've tried: views.py
from django.shortcuts import render
from mysite.forms import sign_up_form
def register(request):
sign_up = sign_up_form(auto_id=False)
context = {'sign_up_form': sign_up}
return render(request, 'mysite/register.html', context)
I need mine widgets
as above.
+3
source to share
1 answer
ModelForms will have default labels marked, so you have to rewind where you don't need labels.
you can define it like this
class sign_up_form(forms.ModelForm):
email = forms.CharField(widget=forms.Textarea, label='')
class Meta:
model = Users
fields =['email']
This method will not contain labels for your form, the other method depends on rendering in the template. You can always avoid shortcuts from the form
<label>MY LABEL</label>
instead{{ form.field.label }}
+6
source to share