如何为mongodb配置settings.py?

时间:2013-08-19 13:52:24

标签: python mongodb

我创建了使用mongo数据库的django web应用程序,我与pymongo联系到mongo

 def load_database():
    mongo = pymongo.Connection('127.0.0.1')
    db = mongo['database'] 

当我尝试加载我的网络应用时,我收到错误

Exception Type:

ImproperlyConfigured



Exception Value:

settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. 


Exception Location:

Python-2.7/lib/python2.7/site-packages/django/db/backends/dummy/base.py in complain, line 15

看起来settings.py配置错误,这是我的settings.py:

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or     
'NAME': '',                      # Or path to database file if using sqlite3.
 # The following settings are not`enter code here` used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '',                      # Empty for localhost through domain sockets or   '
'PORT': '',                      # Set to empty string for default.
}
}

有人能告诉我什么是错的吗?当我加载不与mongo连接的主页时,只加载静态文件,当我点击ontom on hoommpage从mongo数据库获取数据并打印出该数据时,我收到此错误。此外,我尝试了python manage.py syncdb,但收到错误:ImproperlyConfigured:settings.DATABASES配置不正确。请提供ENGINE值。检查设置文档以获取更多详细信

2 个答案:

答案 0 :(得分:2)

为了正确使用mongoDB,您应该安装以下软件包: Django的nonrel, djangotoolbox, Django的mongodb-engine。

然后您可以编辑设置

DATABASES = {
   'default' : {
      'ENGINE' : 'django_mongodb_engine',
      'NAME' : 'my_database'
   }
}

答案 1 :(得分:1)

如果你直接使用pymongo,你可以省略settings.py中的整个DATABASES变量。

如果您不想直接使用pymongo,请考虑查看mongoengine