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']
请参阅^{} 方法的文档
如果在保存之前需要对数据执行某些操作,只需创建一个如下函数:
您只需要创建一个名为**clean\u**nameofdata*的函数,其中nameofdata是字段的名称,因此如果要修改密码字段,您需要:
如果需要修改密码repeat
所以在里面,只要加密你的密码并返回加密的密码。
我是说:
所以当你有效的时候,密码会被加密。
如果需要从POST填写表单、更改任何表单字段值并再次呈现表单,则会出现问题。 以下是解决方案:
然后:
相关问题 更多 >
编程相关推荐