How to add class, id, placeholder attributes to a field in django model forms

前端 未结 9 2094
既然无缘
既然无缘 2020-12-05 00:12

I have a django model like below

models.py

class Product(models.Model):
    name = models.CharField(max_length = 300)
    descripti         


        
9条回答
  •  一向
    一向 (楼主)
    2020-12-05 00:50

    You can do the following:

    class ProductForm(ModelForm):
        name = forms.CharField(label='name ', 
                widget=forms.TextInput(attrs={'placeholder': 'name '}))
    

提交回复
热议问题