关于Django ModelForm渲染时间格式问题

直接定义DateTimeInput或者DateTimeFile是不行的,渲染在html页面中的仍然是Input text类型

解决办法:自定义小部件

class DateInput(forms.DateInput):
    input_type = 'date'

然后设置widgets

widgets = {
            'date' : DateInput(),
        }

此时渲染出来的页面就是

<input type="date" name="data" required id="id_data" />

 

相关文章:

  • 2022-12-23
  • 2022-02-21
  • 2022-01-23
  • 2022-01-02
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-12-07
  • 2021-09-30
  • 2021-07-16
  • 2022-12-23
相关资源
相似解决方案