Override Django form field's name attr

前端 未结 5 1715
谎友^
谎友^ 2020-12-05 11:23

I\'ve built a Django form that submits to a page on another domain (that I don\'t control). The idea is that I have a nicely styled, neatly generated form that fits neatly i

5条回答
  •  情深已故
    2020-12-05 11:40

    It's simple. Just use the attribute 'labels' of the class Meta:

    class AuthorForm(ModelForm):
        class Meta:
            model = Author
            fields = ('name', 'title', 'birth_date')
            labels = {
                'name': 'new_name',
            }
    

    where 'new name' will be the name displayed in the html.

提交回复
热议问题