如何使用Django设置MongoDB

时间:2013-04-13 16:35:39

标签: python django mongodb django-nonrel django-mongodb-engine

我已经关注了如何使用MongoDB设置Django项目的大量教程,但在运行测试命令时仍然会遇到相同的错误:

python manage.py runsever

以下是我一直关注的链接:

http://www.allbuttonspressed.com/blog/django/2010/05/MongoDB-backend-for-Django-nonrel-released

以下是我从上述命令中得到的错误:

Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10d266210>>
Traceback (most recent call last):

File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)

File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)

File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 23, in get_validation_errors
from django.db import models, connection

File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])

File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)

File "/Library/Python/2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])

 File "/Library/Python/2.7/site-packages/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)

 File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)

File "build/bdist.macosx-10.8-intel/egg/django_mongodb_engine/__init__.py", line 13, in <module>

AttributeError: 'tuple' object has no attribute 'insert'

我不知道为什么这不起作用,理想情况下我只想要一个专门用于存储JSON文档的数据库设置。是否有更容易的替代方法将Django与另一个非常适合存储JSON信息的数据库连接起来?

2 个答案:

答案 0 :(得分:0)

澄清:

INSTALLED_APPS应该是元组。

他得到AttributeError: 'tuple' object has no attribute 'insert',因为mongodb无法正确处理元组INSTALLED_APPS。 mongodb中的默认值是插入列表。这已经解决了,但现在它已经消失了。

有建议:

  • 将您的settings.INSTALLED_APPS更改为列表而不是元组。 (这对我不好)
  • 通过添加补丁
  • 更正其代码

答案 1 :(得分:0)

有一个名为djongo的新程序包,用于mongoDB的完全nosql支持:  -https://nesdis.github.io/djongo/

您不能在venv中安装ist:

pip install djongo