我是Mongo DB和Django的新手。我一直在尝试使用Mongo DB作为Django的主要数据库。我按照以下链接安装了MongoDB和Django-nonrel:
django-nonrel的版本,我使用的是1.7。克隆链接:
pip install git+https://github.com/django-nonrel/django@nonrel-1.7
完成所有步骤后,django项目文件中的settings.py看起来像这样:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'blink',
'USER': '',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': 1234,
}
}
INSTALLED_APPS = (
'djangotoolbox',
)
但是在使用以下命令运行manage.py时:
python manage.py runserver
我收到这样的错误,
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x104a95f80>
Traceback (most recent call last):
File "/Users/sunilkumar/blink/lib/python3.3/site-packages/django/utils/autoreload.py", line 222, in wrapper
fn(*args, **kwargs)
File "/Users/sunilkumar/blink/lib/python3.3/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
self.check_migrations()
File "/Users/sunilkumar/blink/lib/python3.3/site-packages/django/core/management/commands/runserver.py", line 159, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/Users/sunilkumar/blink/lib/python3.3/site-packages/django/db/utils.py", line 242, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/sunilkumar/blink/lib/python3.3/site-packages/django/db/utils.py", line 108, in load_backend
return import_module('%s.base' % backend_name)
File "/Users/sunilkumar/blink/lib/python3.3/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1022, in load_module
File "<frozen importlib._bootstrap>", line 1003, in load_module
File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 853, in _load_module
File "<frozen importlib._bootstrap>", line 980, in get_code
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "/Users/sunilkumar/blink/lib/python3.3/site-packages/django_mongodb_engine/base.py", line 265
raise ImproperlyConfigured, exc_info[1], exc_info[2]
^
SyntaxError: invalid syntax
我无法理解错误是什么。有人可以帮忙。?
答案 0 :(得分:3)
您似乎正在使用Python 3.但是django-mongodb-engine
所依赖的django-nonrel
甚至还不支持Python 3。
上面的语法错误实际上在py3中有效,但在py2中没有。因此错误。
也许你应该考虑在这个项目中使用py2。