I have the following django scheme:
forms.py
from django import forms
class ContactForm(forms.Form):
name_param = forms.CharField()
email_param = forms.EmailField()
message_param = forms.CharField(widget=forms.Textarea)
recaptcha_param = ReCaptchaField()
My question is:
I'd like to implement something like this. Also we'd like to enable direct overwrite-as-we-type on the default value.
答案 0 :(得分:7)
您可以在email_param字段中添加占位符属性。所以你的forms.py将是:
from django import forms
class ContactForm(forms.Form):
name_param = forms.CharField()
email_param = forms.EmailField(widget=forms.EmailInput({'placeholder': 'test@example.com'}))
message_param = forms.CharField(widget=forms.Textarea)
recaptcha_param = ReCaptchaField()
答案 1 :(得分:1)
那只是HTML
<input type="email" placeholder="This is used to contact you..." name="email"/>
答案 2 :(得分:0)
注意
forms.EmailField()
不会将小部件作为参数。
你可以这样做的方式可能是
models.EmailField(max_length = 255,默认='你默认值或者是example@email.com')
这比html解决方案更强大,为您提供了在数据库上管理它的方法