如何将Django日期格式更改为dd / mm / yy? [英] How to change Django date format to dd/ mm/ yy?

查看:223
本文介绍了如何将Django日期格式更改为dd / mm / yy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在forms.py:

  class DobForm(forms.ModelForm)
dob = forms.DateField(widget = forms.TextInput(attrs = {'class':'datepicker'}),required = True,input_formats = ['%d /%m /%Y',])

class Meta:
model = Dob

在我的html中:



{pre> $(function(){$(。datepicker)。datepicker({maxDate:'0',dateFormat:'dd-mm-yy'})}); < / script>

表单中的thor wing错误:输入有效日期

解决方案

您需要使django和jquery的格式相同。



为DateField django):

  ...,input_formats = ['%d-%m-%Y',])

并在html中使用:

  ...,dateFormat:'dd-mm-yyyy'})});< / script> 

我希望这有效。


In forms.py:

class DobForm(forms.ModelForm)  
    dob = forms.DateField(widget=forms.TextInput(attrs={'class':'datepicker'}),required=True,input_formats=['%d/%m/%Y',])

    class Meta:
        model = Dob

In my html:

$(function() {$(".datepicker").datepicker({ maxDate: '0',dateFormat: 'dd-mm-yy' })});</script>

Its thorwing error in the form: Enter a valid date

解决方案

You need to make the formats the same for both django and jquery.

Try this for the DateField (django):

...,input_formats=['%d-%m-%Y',])

and in the html use:

...,dateFormat: 'dd-mm-yyyy' })});</script>

I hope this works.

这篇关于如何将Django日期格式更改为dd / mm / yy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆