我正在运行一个应用程序,我需要在MongoDB和Django应用程序之间建立连接
我正在使用以下命令运行应用程序:python manage.py runserver
我在Python 3.5
windows 10 OS
以下是我的settings.py
文件部分,我尝试尝试MongoDB
和Django
之间的连接
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