/ accounts / login / id的TypeError必须是(str,unicode,ObjectId)的实例,而不是<type'int'=“”> </type>

时间:2013-03-19 13:15:18

标签: django mongodb pymongo

这是我mongodb

的第一个示例代码

我正在尝试将djangomongodb联系起来。 我成功完成了注册部分,但是当我尝试登录时显示错误页面。

TypeError at /accounts/login/
id must be an instance of (str, unicode, ObjectId), not type 'int'

我正在使用django用户身份验证,

这是我的网址 的 url(r'^accounts/login/', 'django.contrib.auth.views.login'),

下面是我的全部追溯,

TypeError at /admin/profile/
id must be an instance of (str, unicode, ObjectId), not <type 'int'>
Request Method: GET
Request URL:    http://www.myapp.com/accounts/login/
Django Version: 1.3
Exception Type: TypeError
Exception Value:    
id must be an instance of (str, unicode, ObjectId), not <type 'int'>
Exception Location: /home/sakeer/workspace/entevirtual/lib/python2.7/site-
packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/bson/objectid.py in __validate, line 198
Python Executable:  /home/sakeer/workspace/entevirtual/bin/python
Python Version: 2.7.3
Python Path:    
['/home/sakeer/workspace/enteproject',
 '/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
 '/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/djangotoolbox-0.9.2-py2.7.egg',
 '/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg',
 '/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg',
 '/home/sakeer/workspace/entevirtual/lib/python27.zip',
 '/home/sakeer/workspace/entevirtual/lib64/python2.7',
 '/home/sakeer/workspace/entevirtual/lib64/python2.7/plat-linux2',
 '/home/sakeer/workspace/entevirtual/lib64/python2.7/lib-tk',
 '/home/sakeer/workspace/entevirtual/lib64/python2.7/lib-old',
 '/home/sakeer/workspace/entevirtual/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7',
 '/usr/lib/python2.7',
 '/usr/lib64/python2.7/lib-tk',
 '/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages',
 '/home/sakeer/workspace/enteproject/lib',
 '/home/sakeer/workspace/enteproject/lib']

我缺少的地方

1 个答案:

答案 0 :(得分:2)

似乎是Django中的一个错误,它假设用户ID总是整数,这对于关系数据库是有意义的。在使用Mongodb的情况下,键或_id将成为对象ID。

这有一些开放的错误,似乎再次出现(例如,这一个https://code.djangoproject.com/ticket/14881)。目前,我已经在django用户帐户中添加了对此(https://github.com/pinax/django-user-accounts/issues/103)的评论,这似乎很合适。

可能需要修补补丁。

奇怪的是,我让它与django 1.5合作,使用mongoengine,但在升级到django 1.6.1后,问题又回来了。