TypeError at /accounts/login/ id must be an instan

2019-02-27 09:43发布

This is my first example code for mongodb

I am trying to connect my django with mongodb. I did my registration part successfully, But when I am trying to log in its showing an error page.

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

I am using django user authentication,

this is my url url(r'^accounts/login/', 'django.contrib.auth.views.login'),

below is my full traceback,

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']

where and what i am missing

1条回答
一纸荒年 Trace。
2楼-- · 2019-02-27 10:18

Seems to be a bug in Django, which assumes that user ids are always ints, which would make sense for a relational database. In the case of using Mongodb, the key or _id is going to be an object ID.

There are open bugs on this, which seem to pop up over again (for instance, this one https://code.djangoproject.com/ticket/14881 ) . For the moment, I've added a comment to this one ( https://github.com/pinax/django-user-accounts/issues/103 ) in django user accounts, which seems to be a good fit.

It may require a patch to fix.

Oddly enough, I had it working with django 1.5, with mongoengine, but after upgrading to django 1.6.1, the issue is back.

查看更多
登录 后发表回答