DEV Community

Reishi Mitani
Reishi Mitani

Posted on

3 1

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay