问题描述
我想知道我制作的表格有什么问题。
有人能指出哪里出了问题吗?
from datetime import date
today = date.today()
currentDate = today.strftime("%m/%d/%Y")
class DateInput(forms.DateInput):
input_type = 'date'
class salesForm(forms.Form):
entryDateField = forms.DateField(label="Entry Date",widget=DateInput(attrs={'value': currentDate,'readonly': 'readonly','class':'col-sm-8'}))
解决方法
我认为您应该使用 initial
属性。
from datetime import date
def current_date():
today = date.today()
return today.strftime("%m/%d/%Y")
# in your form class
date = forms.DateField(initial=current_date)