/ accounts / login / id中的TypeError必须是(str,unicode,ObjectId)的实例,而不是< type'int'> [英] TypeError at /accounts/login/ id must be an instance of (str, unicode, ObjectId), not <type 'int'>

查看:216
本文介绍了/ accounts / login / id中的TypeError必须是(str,unicode,ObjectId)的实例,而不是< type'int'>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个例子代码 mongodb



我试图连接我的 django mongodb
我成功注册了一部分,但是当我尝试登录时显示错误页面。

  TypeError在/ accounts / login / 
id必须是(str,unicode,ObjectId)的一个实例,而不是类型'int'

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



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



完全追踪

  / admin / profile / 
中的TypeError必须是(str,unicode,ObjectId ),而不是< type'int'>
请求方法:GET
请求URL:http://www.myapp.com/accounts/login/
Django版本:1.3
异常类型:TypeError
异常值:
id必须是(str,unicode,ObjectId)的实例,而不是< type'int'>
异常位置:/home/sakeer/workspace/entevirtual/lib/python2.7/site-
packages / pymongo-2.4.2-py2.7-linux-x86_64.egg / bson / objectid。 py在__validate,行198
Python可执行文件:/ home /清除器/工作区/ entevirtual / bin / python
Python版本:2.7.3
Python路径:
['/ home / deliciouser / workspace / enteproject',
'/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/ home /出现者/工作区/ 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 / clarityer / workspace / enteproject / lib',
'/ home /清除者/工作区/ enteproject / lib']

我在哪里和我缺少

解决方案

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



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



它可能需要一个修补程序。



奇怪的是,我已经用django 1.5和mongoengine一起工作,但升级到django 1.6.1后,问题就是回来了。 p>

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

解决方案

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.

这篇关于/ accounts / login / id中的TypeError必须是(str,unicode,ObjectId)的实例,而不是&lt; type'int'&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆