[英]Django Mongoengine unable to connect to MongoDB
We have build our environment using Django 1.7
, Mongoengine 0.8.7
, MongoDB 2.4.7
and Python 3.4
. 我们已经使用Django 1.7
, Mongoengine 0.8.7
, MongoDB 2.4.7
和Python 3.4
构建了环境。
We have installed django-rest-framework , but when we try to run the example of the website, we get the following error: 我们已经安装了django-rest-framework ,但是当我们尝试运行该网站的示例时,出现以下错误:
ImproperlyConfigured at /users/
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
Request Method: GET
Request URL: http://localhost:8000/users/
Django Version: 1.7
Exception Type: ImproperlyConfigured
Exception Value:
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
Exception Location: /Users/user_name/Development/projects/current_project/lib/python3.4/site-packages/django/db/backends/dummy/base.py in complain, line 18
Python Executable: /Users/user_name/Development/projects/current_project/bin/uwsgi
Python Version: 3.4.1
Python Path:
['.',
'',
'/Users/user_name/Development/projects/current_project/lib/python34.zip',
'/Users/user_name/Development/projects/current_project/lib/python3.4',
'/Users/user_name/Development/projects/current_project/lib/python3.4/plat-darwin',
'/Users/user_name/Development/projects/current_project/lib/python3.4/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
'/Users/user_name/Development/projects/current_project/lib/python3.4/site-packages']
This is what we have changed in our settings.py
according to the documentation that we have found: 这是我们根据发现的文档在settings.py
进行的更改:
import mongoengine
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
}
}
mongoengine.connect('database_name', username='root', password='password')
SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'
For what we have seen, if we connect through the mongoengine.connect
method the ENGINE parameter should not be ignored, but we are finding this error instead. 就我们所看到的而言,如果我们通过mongoengine.connect
方法进行连接,则不应忽略ENGINE参数,但实际上是发现了此错误。 Anyone knows how we could solve it? 有人知道我们怎么解决吗?
I used mongodb setting at the end of settings.py file like this 我像这样在settings.py文件的末尾使用了mongodb设置
# Mongodb settings
AUTHENTICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
)
MONGO_DATABASE_NAME = 'prod'
MONGOENGINE_USER_DOCUMENT = 'mongoengine.django.auth.User'
SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'
from mongoengine import connect
connect(MONGO_DATABASE_NAME)
add this to settings.py: 将此添加到settings.py:
AUTHENTICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
)
maybe this help you. 也许这对您有帮助。
After some research, we have found how to solve the issue. 经过研究,我们找到了解决问题的方法。
Instead of following the example that can be found on the http://www.django-rest-framework.org/ we have followed the Quickstart guide . 我们没有遵循http://www.django-rest-framework.org/上的示例,而是遵循了快速入门指南 。 Following this guide, we have solved our problem. 遵循本指南,我们已经解决了我们的问题。
Many thanks for all the answers! 非常感谢您提供所有答案!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.