2

我以这种方式安装和配置了 Django/MongoDB!

点安装虚拟环境

源 myproject/bin/激活

pip install hg+https://bitbucket.org/wkornewald/django-nonrel

pip install hg+https://bitbucket.org/wkornewald/djangotoolbox

pip install git+https://github.com/django-nonrel/mongodb-engine

所有这些操作都成功了!

现在,当我像这样更改 settings.py 文件时:

DATABASES = {
    'default': {
        'ENGINE': 'django_mongodb_engine', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'mong_db',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }

出现令人费解的错误:</p>

Error was: No module named django_mongodb_engine.base

显然django_mongodb_engine 安装成功。但是为什么会出现这个错误呢?

顺便说一句,原谅我糟糕的英语!

4

1 回答 1

1

我完成了与您相同的步骤,然后打开了一个 Python shell:

$ python
>>> import django_mongodb_engine.base
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/emptysquare/.virtualenvs/foo/lib/python2.7/site-packages/django_mongodb_engine/base.py", line 4, in <module>
    from django.db.backends.signals import connection_created
  File "/Users/emptysquare/.virtualenvs/foo/lib/python2.7/site-packages/django/db/__init__.py", line 14, in <module>
    if not settings.DATABASES:
  File "/Users/emptysquare/.virtualenvs/foo/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/Users/emptysquare/.virtualenvs/foo/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

但如果我这样做:

$ DJANGO_SETTINGS_MODULE=settings python
>>> import django_mongodb_engine.base

... 有用。

你可以设置 DJANGO_SETTINGS_MODULE 并尝试在 Python shell 中导入 django_mongodb_engine.base 吗?

于 2012-03-29T14:42:53.817 回答