Django和Pymongo连接没有建立

时间:2017-09-23 10:24:32

标签: python django mongodb python-3.5

我正在运行一个应用程序,我需要在MongoDB和Django应用程序之间建立连接 我正在使用以下命令运行应用程序:python manage.py runserver

我在Python 3.5

上使用windows 10 OS

以下是我的settings.py文件部分,我尝试尝试MongoDBDjango之间的连接

from pymongo import MongoClient
# MONGO_DATABASE_NAME = 'testdb'
# MONGO_HOST = 'localhost'
# MONGO_PORT = 27017
MongoClient("mongodb://localhost:27017")


SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'

我收到连接错误的部分是:

if form.is_valid():
    # process the data in form.cleaned_data as required
    # ...
    # redirect to a new URL:
    # print (form.cleaned_data['for_analysis'])
    mongo = API_Mongo()
    mongo.content = form.cleaned_data['for_analysis']
    mongo.save()
    logger.debug('Text Data saved to Mongo DB')
    data = form.cleaned_data['for_analysis'].encode("utf-8")  

错误发生在mongo.save()

以下是错误:

Exception Type: ConnectionError at /analyze/
Exception Value: You have not defined a default connection

我的完整TraceBack可在此处找到:TraceBack

0 个答案:

没有答案