Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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)

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/

'MetaDict' object has no attribute 'pk'

Request Method: POST

Request URL: http://myapp.dev:8000/admin/login/

Django Version: 1.8

Exception Type: AttributeError

Exception Value: 'MetaDict' object has no attribute 'pk'

Exception Location: c:\Programs\Python34\lib\site-packages\django\contrib\auth__init__.py in login, line 111

Python Executable: c:\Programs\Python34\python.exe

Python Version: 3.4.2

P.S: I have also tried customizing Login Process by writing URL patterns, template and views, but will get same error on calling "login()" function.

like image 879
R‌‌‌.. Avatar asked Nov 10 '22 15:11

R‌‌‌..


1 Answers

I had a same issue that you guys were having. I created a new github project to resolve my issue. You can download it or modify it or extract code for your own use by going to 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

like image 76
nixdaemon Avatar answered Nov 14 '22 22:11

nixdaemon