如何在视图中更改表单的占位符?
def myview(request):
form = MyForm()
form.widget.attrs.placeholder = 'Replace placeholder value'
答案 0 :(得分:0)
您可以动态设置占位符到表单字段:
def someview(request):
form = SomeForm(..)
if some_condition:
form.fields['yourfield'].widget.attrs['placeholder'] = instance.yourfield