在Python 2.6.4上使用Django 1.1,尝试执行以下命令:
user = User.objects.create_user(username, email, password)
这三个值来自form.cleaned_data,并且已经过验证。我收到这个错误:
'dict' object has no attribute 'strip'
Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/home/jason/bandistry/../bandistry/musician/views.py" in signup
140. user = User.objects.create_user(username, email_address, password)
File "/usr/lib/pymodules/python2.6/django/contrib/auth/models.py" in create_user
100. user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now)
Exception Type: AttributeError at /musician/signup
Exception Value: 'dict' object has no attribute 'strip'
然后我尝试使用以下方法手动创建用户:
user = User(username=username, email=email_address)
user.set_password(password)
user.is_active = True
user.save()
我收到此错误:
Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/home/jason/bandistry/../bandistry/musician/views.py" in signup
144. user.save()
File "/usr/lib/pymodules/python2.6/django/db/models/base.py" in save
410. self.save_base(force_insert=force_insert, force_update=force_update)
File "/usr/lib/pymodules/python2.6/django/db/models/base.py" in save_base
495. result = manager._insert(values, return_id=update_pk)
File "/usr/lib/pymodules/python2.6/django/db/models/manager.py" in _insert
177. return insert_query(self.model, values, **kwargs)
File "/usr/lib/pymodules/python2.6/django/db/models/query.py" in insert_query
1087. return query.execute_sql(return_id)
File "/usr/lib/pymodules/python2.6/django/db/models/sql/subqueries.py" in execute_sql
320. cursor = super(InsertQuery, self).execute_sql(None)
File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py" in execute_sql
2369. cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.6/django/db/backends/util.py" in execute
19. return self.cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.6/django/db/backends/mysql/base.py" in execute
84. return self.cursor.execute(query, args)
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py" in execute
151. query = query % db.literal(args)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py" in literal
247. return self.escape(o, self.encoders)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py" in unicode_literal
185. return db.literal(u.encode(unicode_literal.charset))
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py" in literal
247. return self.escape(o, self.encoders)
Exception Type: RuntimeError at /musician/signup
Exception Value: maximum recursion depth exceeded
其他人得到这些错误并知道我做错了什么?
答案 0 :(得分:2)
似乎email_address不是真正的字符串('dict'对象没有属性'strip'),你能为我们转储用户名,电子邮件和密码的值吗?