1

我已经学习了许多关于如何使用 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 信息的数据库连接起来?

4

2 回答 2

0

为了澄清:

INSTALLED_APPS 应该是元组。

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

有以下建议:

  • 将您的 settings.INSTALLED_APPS 更改为列表而不是元组。(这对我不利)
  • 通过添加补丁来更正他们的代码
于 2013-04-13T16:53:29.570 回答
0

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

你不能在你的venv中安装ist:

pip install djongo
于 2019-04-12T12:09:33.573 回答