0

I'm getting an error in my Django Project and I would like to find a solution.

I developped my project with MySQL Database, but after some discussions, I would like to replace MySQL by NoSQL Database (and Django ORM commands by Django MongoDB commands) like MongoDB for different reasons :

  • Ability to handle billions lines
  • Ability to make Big Data (Hadoop, ...)

My Django project settings looks like :

import mongoengine 
from mongoengine import connect

AUTHENTICATION_BACKENDS = (
    'mongoengine.django.auth.MongoEngineBackend',
)

SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'

DATABASES = { 
     'default': {
          'ENGINE': 'django.db.backends.dummy' 
     }
}

MONGO_DATABASE_NAME = 'XXX'
MONGO_HOST = '172.30.10.X'
MONGO_PORT = 27017
connect(MONGO_DATABASE_NAME, host=MONGO_HOST, port=MONGO_PORT)

And, when I run : python manage.py runserver

I get :

System check identified 1 issue (0 silenced).
March 20, 2017 - 10:33:20
Django version 1.10.3, using settings 'Etat_civil.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <function wrapper at 0x104994140>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
    handler = self.get_handler(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/usr/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 59, in get_internal_wsgi_application
    sys.exc_info()[2])
  File "/usr/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    return import_string(app_path)
  File "/usr/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/valentinjungbluth/Desktop/Django/Etat_civil/Etat_civil/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 58, in load_middleware
    mw_instance = mw_class()
  File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py", line 15, in __init__
    engine = import_module(settings.SESSION_ENGINE)
  File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
django.core.exceptions.ImproperlyConfigured: WSGI application 'Etat_civil.wsgi.application' could not be loaded; Error importing module: 'No module named django.sessions'

I know that lastest mongoengine updates doesn't support sessions, so I downloaded mongoengine==0.9.0 but it seems to not work.

Do you have an idea ?

Essex
  • 6,042
  • 11
  • 67
  • 139
  • Do you have in your `MIDDLEWARE` settings this: `'django.contrib.sessions.middleware.SessionMiddleware'` and in your `INSTALLED_APPS` this: `'django.contrib.sessions'` ? – nik_m Mar 20 '17 at 10:48
  • @nik_m Yes exactly ^^ Django is used on my MacOSX in localhost and the MongoDB is located on a distant server – Essex Mar 20 '17 at 10:50
  • Not a duplicate, because I already tried the answers : install an earlier version ... – Essex Mar 20 '17 at 10:59
  • I voted to close as a duplicate -- as I said in the comment of the other question, you can't expect mongoengine 0.9.0 to support recent versions of Django. If your question is then "how can I use mongodb and Django together, then that's asking for recommendations which is off-topic for Stack Overflow. – Alasdair Mar 20 '17 at 11:28
  • Ok I understand. It's too bad that it doesn't exist a very good solution between Django and NoSQL (MongoDB, Cassandra, ...). I will make more researches in order to get informations and supported NoSQL version. – Essex Mar 20 '17 at 13:04

1 Answers1

0

I haven't experienced using mongodb as an engine but the Django documentation says the database should be declared using this format: Read https://docs.djangoproject.com/en/1.10/ref/databases/

DATABASES = {
    'default': {
        'ENGINE': django_mongodb_engine',
        'NAME': 'XXX',
        'USER': 'a_user',
        'PASSWORD': 'a_password',
        'HOST': '',
        'PORT': '',
    }
}
jonilyn2730
  • 465
  • 9
  • 21
  • Yes, but I'm following this little tutorial : http://staltz.com/djangoconfi-mongoengine/#/16 It's the first time I'm using MongoDB too so I don't know exactly what I've to configure – Essex Mar 20 '17 at 10:52
  • The tutorial was published last 2013, so I think the author is using an older version of Django. I think this could be a good reference: https://django-mongodb-engine.readthedocs.io/en/latest/topics/setup.html – jonilyn2730 Mar 20 '17 at 10:59
  • `mongodb-engine` is supported up to now ? – Essex Mar 20 '17 at 11:04
  • It seems so. The reference link I gave was edited last March 14, 2017 – jonilyn2730 Mar 20 '17 at 11:08