新建一个 form,如下设置:
from django import forms
class MyInfoForm(forms.Form):
user_id = forms.IntegerField(
widget=forms.TextInput(attrs={'readonly': 'readonly'}), # 设置input为只读
initial='默认user_id' # 设置默认值
)
user_name = forms.CharField(
widget=forms.TextInput(attrs={'readonly': 'readonly'}),
initial='默认user_name'
)
email = forms.EmailField(
widget=forms.TextInput(attrs={'readonly': 'readonly'}),
initial='默认email'
)
网页效果如下:
表单处于不可编辑的