CurrentDate 变量未在输入框中显示为值

CurrentDate variable not display as Value in input box

我想知道我制作的表格有什么问题。

这是一个日期输入文本框,它会自动填充当前日期。

谁能指出问题所在?

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)