How do I remove Label text in Django generated form?

前端 未结 3 893
深忆病人
深忆病人 2021-02-19 16:39

I have a form that is displaying well only for the label text that I don\'t want and I have tried all I could to let it off my form but it won\'t just go...

form

相关标签:
3条回答
  • 2021-02-19 16:56

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

    0 讨论(0)
  • 2021-02-19 16:59

    just set a class for the field in the widgets and in your style add:

    .ClassName label{
        display: none;
    }
    
    0 讨论(0)
  • 2021-02-19 17:03

    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 = ""
    
    0 讨论(0)
提交回复
热议问题