【发布时间】:2012-02-14 01:11:12
【问题描述】:
if request.method == 'POST':
userf = UsersModelForm(request.POST)
username = userf.data['username']
password = userf.data['password']
passwordrepeat = userf.data['passwordrepeat']
email = userf.data['email']
我试过了:
tempSalt = bcrypt.gensalt()
password = bcrypt.hashpw(password,tempSalt)
passwordrepeat = bcrypt.hashpw(passwordrepeat,tempSalt)
userf.data['password'] = password
userf.data['passwordrepeat'] = passwordrepeat
但我得到了错误。如何在保存之前更改userf.data['password'] 和userf.data['passwordrepeat'] 的值?
错误:
AttributeError at /register
This QueryDict instance is immutable
Request Method: POST
Request URL: http://127.0.0.1:8000/register
Django Version: 1.3.1
Exception Type: AttributeError
Exception Value:
This QueryDict instance is immutable
Exception Location: /usr/local/lib/python2.6/dist-packages/django/http/__init__.py in _assert_mutable, line 359
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/user1/djangoblog',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/pymodules/python2.6/gtk-2.0']
【问题讨论】:
-
你有什么样的错误?验证错误,完整性错误?您必须始终发布错误消息。总是。
-
我已经更新了错误,再看一遍就明白了。
-
我们也需要你想做的事情:设置一个默认值,如果值不存在就设置一个值,如果它不好就更正一个值,等等。django 表单上有几个钩子。
-
我已经更新了原始帖子/问题。再看一遍就明白了。
-
它没有告诉我们你想做什么,它告诉我们使用你在做什么。你想要什么结果?不是在编程级别,而是在功能级别。
标签: python django forms model save