5

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.

3
  • 1
    have you find any solution.I has the same error Commented Apr 28, 2015 at 13:30
  • @himanshudua Unfortunately not yet. I've wrote a temporary user manager class for now. As soon as finding any solution I will update my code and this question. Commented Apr 28, 2015 at 15:36
  • @himanshudua got the solution ? Commented Feb 13, 2016 at 8:50

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Change in this file 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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.