Django - Auth with mongoengine DB

后端 未结 3 1049
清歌不尽
清歌不尽 2020-12-08 17:31

I want to handle authentications in my Django project with my mongoengine db.

I tried a few examples about this stuff answered in old questions but it didn\'t run. I

3条回答
  •  春和景丽
    2020-12-08 18:30

    Hey I'm in the same situation as you are. As I can figure out you have these in the settings.py

    AUTH_USER_MODEL = 'mongo_auth.MongoUser'
    MONGOENGINE_USER_DOCUMENT = 'mongoengine.django.auth.User'
    

    And this in the installed apps

    'mongoengine.django.mongo_auth'
    

    This means that now you are using the Mongoengine authentication method, The first line you are using imports the DJANGO authentication method, so there's the problem. You are not creating any databases in mongodb, but in the dummy one you have set up with the backend.dummy in the ORM of Django.

    I don't know how to use mongoengine's auth method, if you figure it out please explain it to me too ;) I hope I clarified you a little about the problem we both face here. It's just a matter of reading more profoundly the docs.

    EDIT: (1 minute after the answer) I found this in the documentation you linked to:

    MongoEngine includes a Django authentication backend, which uses MongoDB. >The User model is a MongoEngine Document, but implements most of the >methods and attributes that the standard Django User model does - so the >two are moderately compatible.

    so that means that in your case, swap the

    from django.contrib.auth import User
    

    to

    from mongoengine.django.auth import User
    

提交回复
热议问题