简体   繁体   English

无法使用Django设置mongodb

[英]Unable to setup mongodb with Django

My Settings.py file has 我的Settings.py文件有

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

When I try to run the django I get the following error. 当我尝试运行django ,出现以下错误。 I have attached the screenshot of the error 我已附上错误的屏幕截图

I refered to this document https://django-mongodb-engine.readthedocs.io/en/latest/topics/setup.html MongoDb is up and running in the port 27017 Django Version:1.7 Python :3.4.3 我参考了此文档https://django-mongodb-engine.readthedocs.io/en/latest/topics/setup.html MongoDb已在端口27017上启动并运行Django版本:1.7 Python:3.4.3

Please suggest the solution to setup the mongodb with django. 请提出使用django设置mongodb的解决方案。

I found few reasons why MongoDb-engine(Python ORM form mongo database) tutorial was not working: 我发现了MongoDb-engine(Python ORM form mongo database)教程不起作用的几个原因

  1. It supports Python version <3.5 它支持Python版本<3.5
  2. And to connect to the database you should put the following code in settings.py 为了连接到数据库,您应该将以下代码放入settings.py

     DATABASES = { 'default' : { 'ENGINE' : 'django_mongodb_engine', 'NAME' : 'my_database' } } 
  3. They don't have active developer community 他们没有活跃的开发者社区

Solution: Follow this tutorial for python>=3.5 and use mongoengine a python object data mapper for MongoDb. 解决方案:按照本教程的python> = 3.5进行操作,并使用mongoengine一个用于MongoDb的python对象数据映射器。 http://docs.mongoengine.org/tutorial.html to connect to the database put the following code in your project settings.py http://docs.mongoengine.org/tutorial.html连接到数据库将以下代码放入您的项目settings.py

DATABASES = {
        'default' : {
                   'ENGINE': 'django.db.backends.dummy'
                    }
         }

from mongoengine import *
connect('dbname') #Database name that you want to use it for the project 

For more info on Development 有关开发的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM