在尝试将form.cleaned_data
保存在postgres数据库中时,我在django中遇到了问题。
user_instance.first_name = form.cleaned_data['first_name']
数据以这种方式保存(u'Firstname',)
,带有'u'前缀和括号,就像我在数据库中保存元组一样。
我在mysql数据库中使用了这么多次,以前从未发生过,
我的django版本是1.3.1
更新
我正以这种方式使用逗号 user_profile.phone_area = phone_area, user_profile.phone_number = phone_number, user_profile.email = email,我编辑了其他人的源代码并忘了删除逗号,这就是它生成元组的原因。谢谢你的帮助
答案 0 :(得分:1)
除了验证,form.clean_data()
将对Python数据类型执行一些隐式转换。您可以通过使用str()
或内置unicode()
包装返回的值来执行显式转换。然后,使用strip("(''),")
格式化字符串。