我的表单中有一个名为生日的字段,例如:
class Personal_info_updateForm(forms.Form):
birthdate = forms.DateField(widget=SelectDateWidget(years=[y for y in range(1930,2050)]))
..
..
视图.py
def personal_info(request):
mc = MenuCategories()
listCategories = mc.getCategories()
oe = OEConnector()
if request.method == 'POST':
f1 = Personal_info_updateForm(request.POST)
print request.POST
if f1.is_valid():
first_name = f1.cleaned_data['first_name']
last_name = f1.cleaned_data['last_name']
c=[last_name,first_name]
name = " ".join(c)
print name
birthdate = f1.cleaned_data['birthdate']
birthdate_year,birthdate_month,birthdate_day=['','','']
birthdate = [birthdate_year,birthdate_month,birthdate_day]
c=" ".join(birthdate)
print birthdate
title = f1.cleaned_data['title']
print title
email = f1.cleaned_data['email']
mobile = f1.cleaned_data['mobile']
phone = f1.cleaned_data['phone']
result = update_details(name,first_name,last_name,birthdate,email,mobile,phone)
print result
return HttpResponse('/Info?info="Congratulations, you have successfully updated the information with aLOTof"')
a1.html 我将整个表单称为
<form action="" method="POST">
<table style="color:black;text-align:left; margin-left: 20px;">
{{ form.as_table }}
</table>
<input type="submit" value="UPDATE">
</form>
我希望将我的生日值存储在 Postgresql 中。但它不起作用,所以我研究了我需要将它转换为 DateTime 字段,因为日期字段对象完全不同。请告诉我如何转换,以便我可以摆脱这个问题。我把它当作一个字符串..
提前致谢