DEV Community

Reishi Mitani
Reishi Mitani

Posted on

Deleting the Form Field Label in Django

The label Comment Text kept appearing on the form.

Alt Text

By adding the labels dictionary in the form file, I was able to get rid of the label.



class CommentForm(forms.ModelForm):

    class Meta:
        model = Comment
        fields = ['comment_text', ]
        labels = {
            "comment_text": ""
        }



Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
taheerg profile image
Tahir Goni Tahir • Edited

You can also add the init method and assign your field label as empty.

def __init__(self, *args, **kwargs):
    super(ModelForm, self).__init__(*args, **kwargs)
    self.fields['name'].label = ""
Enter fullscreen mode Exit fullscreen mode

I have attached a picture.