Django Mongoengine无法连接到MongoDB [英] Django Mongoengine unable to connect to MongoDB

查看:382
本文介绍了Django Mongoengine无法连接到MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 Django 1.7 Mongoengine 0.8.7 MongoDB构建我们的环境2.4.7 Python 3.4



我们已经安装了 django-rest-framework ,但是当我们尝试运行网站的示例时,我们会收到以下错误: / p>

 在/ users / 

settings.DATABASES中配置不正确配置不正确。请提供ENGINE值。检查设置文档以获取更多详细信息。

请求方法:GET
请求URL:http:// localhost:8000 / users /
Django版本:1.7
异常类型:不正确配置
异常值:

settings.DATABASES配置不正确。请提供ENGINE值。检查设置文档以获取更多详细信息。

异常位置:/Users/user_name/Development/projects/current_project/lib/python3.4/site-packages/django/db/backends/dummy/base.py抱怨行18
Python可执行文件:/ Users / user_name / Development / projects / current_project / bin / uwsgi
Python版本:3.4.1
Python路径:

['。',
'',
'/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',密码='密码')


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

对于我们看到的,如果我们通过 mongoengine.connect 方法连接,ENGINE参数不应该被忽略,而是我们发现这个错误。任何人都知道我们如何解决它?

解决方案

经过一些研究,我们已经找到了如何解决这个问题。

而不是按照 http: //www.django-rest-framework.org/ ,我们遵循了快速入门指南。按照本指南,我们已经解决了我们的问题。



非常感谢所有答案!


We have build our environment using Django 1.7, Mongoengine 0.8.7, MongoDB 2.4.7 and 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:

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:

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. Anyone knows how we could solve it?

解决方案

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. Following this guide, we have solved our problem.

Many thanks for all the answers!

这篇关于Django Mongoengine无法连接到MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆