我们使用Django 1.7
,Mongoengine 0.8.7
,MongoDB 2.4.7
和Python 3.4
构建了我们的环境。
我们安装了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']
根据我们找到的文档,这是我们在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'
对于我们所看到的,如果我们通过mongoengine.connect
方法连接,则不应忽略ENGINE参数,但我们发现此错误。有谁知道我们如何解决它?
答案 0 :(得分:3)
我在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)
答案 1 :(得分:0)
将此添加到settings.py:
AUTHENTICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
)
也许这可以帮到你。
答案 2 :(得分:0)
经过一番研究,我们找到了解决问题的方法。
我们没有按照http://www.django-rest-framework.org/上可以找到的示例,而是遵循Quickstart guide。按照本指南,我们已经解决了我们的问题。
非常感谢所有答案!