[英]Django auth error when using mongoengine
I am using mongoengine (v0.9) as a mapper for my Django (v1.8) project running by Python 3.4. 我使用mongoengine(v0.9)作为我的由Python 3.4运行的Django(v1.8)项目的映射器。
Although I have added following codes to settings.py file, I still keep receiving this error while a user try to connect to admin using django default admin process) 虽然我已将以下代码添加到settings.py文件中,但是当用户尝试使用django默认管理进程连接到admin时,我仍然会收到此错误
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mongoengine.django.mongo_auth',
'myapp',
)
AUTHENTICATION_BACKENDS = ('mongoengine.django.auth.MongoEngineBackend',)
SESSION_ENGINE = 'mongoengine.django.sessions'
connect('mymongodb')
AttributeError at /admin/login/
/ admin / login /中的AttributeError
'MetaDict' object has no attribute 'pk'
'MetaDict'对象没有属性'pk'
Request Method: POST
请求方法:POST
Request URL: http://myapp.dev:8000/admin/login/
请求网址: http : //myapp.dev : 8000 / admin / login /
Django Version: 1.8
Django版本:1.8
Exception Type: AttributeError
异常类型:AttributeError
Exception Value: 'MetaDict' object has no attribute 'pk'
异常值:'MetaDict'对象没有属性'pk'
Exception Location: c:\\Programs\\Python34\\lib\\site-packages\\django\\contrib\\auth__init__.py in login, line 111
异常位置:c:\\ Programs \\ Python34 \\ lib \\ site-packages \\ django \\ contrib \\ auth__init __。py in login,line 111
Python Executable: c:\\Programs\\Python34\\python.exe
Python可执行文件:c:\\ Programs \\ Python34 \\ python.exe
Python Version: 3.4.2
Python版本:3.4.2
PS: I have also tried customizing Login Process by writing URL patterns, template and views, but will get same error on calling "login()" function. PS:我也尝试通过编写URL模式,模板和视图来自定义登录过程,但是在调用“login()”函数时会出现相同的错误。
I had a same issue that you guys were having. 我有同样的问题,你们有。 I created a new github project to resolve my issue.
我创建了一个新的github项目来解决我的问题。 You can download it or modify it or extract code for your own use by going to https://github.com/robintiwari/django-me .
您可以通过访问https://github.com/robintiwari/django-me下载或修改它或提取代码供您自己使用。 Please let me know if you have any questions on how to use it.
如果您对如何使用它有任何疑问,请与我们联系。 I also have an example project regarding configuration.
我还有一个关于配置的示例项目。 To be specific, you should find an answer on this code https://github.com/robintiwari/django-me/blob/master/djangome/mongo_auth/middlewares.py
具体来说,你应该找到这个代码的答案https://github.com/robintiwari/django-me/blob/master/djangome/mongo_auth/middlewares.py
Change in this file c:\\Programs\\Python34\\lib\\site-packages\\django\\contrib\\auth__init__.py 更改此文件c:\\ Programs \\ Python34 \\ lib \\ site-packages \\ django \\ contrib \\ auth__init __。py
try:
request.session[SESSION_KEY] = user._meta.pk.value_to_string(user)
except Exception:
request.session[SESSION_KEY] = user.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.