38👍
In ModelForms there will be default labels so you have to over-ride 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 include labels for your form, other method depends on rendering in template. You can always avoid labels from form
<label>MY LABEL</label>
instead of {{ form.field.label }}
12👍
In __init__
method set your field label as empty.This will remove label text.
def __init__(self, *args, **kwargs):
super(sign_up_form, self).__init__(*args, **kwargs)
self.fields['email'].label = ""
- [Django]-Getting Values of QuerySet in Django
- [Django]-Altering one query parameter in a url (Django)
- [Django]-Annotate a queryset with the average date difference? (django)
2👍
If you’re wanting to remove all labels, you can use:
class sign_up_form(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for key, field in self.fields.items():
field.label = ""
- [Django]-Django-taggit – how do I display the tags related to each record
- [Django]-How do I install psycopg2 for Python 3.x?
- [Django]-Altering one query parameter in a url (Django)
Source:stackexchange.com