Django - MongoDB:(无法连接到localhost:27017)连接被拒绝 [英] Django - MongoDB: (could not connect to localhost:27017) Connection refused
问题描述
在settings.py
DATABASES = {
'default':{
'ENGINE':'django_mongodb_engine',
'NAME' :'my_database'
}
}
在firstapp.models.py
从django.db导入模型
从djangotoolbox.fields导入ListField
class Post( model.Model):
title = models.CharField()
text = models.TextField()
tags = ListField()
comments = ListField()
在我的shell(python manage.py shell)中,我尝试运行:
$ b $来自mydjango.firstapp.models的b
Post
post = Post.objects.create();
但是我不断得到以下内容: DatabaseError:无法连接到localhost:27017: Errno 61]拒绝连接(完整追踪)
如果我将settings.py切换到以下内容:
DATABASES = {
'default':{
'ENGINE':'django_mongodb_engine',
'NAME':'my_database',
'USER':'',
'PASSWORD':'',
' HOST':'localhost',
'PORT':'27017',
'SUPPORTS_TRANSACTIONS':False,
},
}
我在shell中收到此错误:不正确配置:端口必须是int的实例
您是否分别设置了MongoDB?你如何链接似乎没有超过MongoDB配置。它假定数据库已经在运行。在任何情况下,MongoDB似乎都会被关闭,或者至少在别的地方听。
最后一个错误(... int int)只是因为你指定了'27017'
(一个字符串),而不是配置字典中的 27017
。但即使如此,它应该等同于第一个简单的配置。
I am having issues getting mongodb working with Django, my setup is Mac OS X 10.7. I followed the tutorial available here: http://django-mongodb.org/topics/setup.html . I have tried with both virtualenv and without (this is my first time installing django so I shouldn't have any conflicts).
In settings.py
DATABASES = {
'default' : {
'ENGINE' : 'django_mongodb_engine',
'NAME' : 'my_database'
}
}
In firstapp.models.py
from django.db import models
from djangotoolbox.fields import ListField
class Post(models.Model):
title = models.CharField()
text = models.TextField()
tags = ListField()
comments = ListField()
In my shell (python manage.py shell), I try running:
from mydjango.firstapp.models import Post
post = Post.objects.create();
But I keep getting the following: DatabaseError: could not connect to localhost:27017: [Errno 61] Connection refused (full traceback)
If I switch settings.py to the following:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'my_database',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '27017',
'SUPPORTS_TRANSACTIONS': False,
},
}
I get this error in the shell: ImproperlyConfigured: port must be an instance of int
Did you setup MongoDB separately? The howto you link doesn't seem to go over the MongoDB configuration. It assumes the database is already running. In any case MongoDB seems down, or is at least listening somewhere else.
The last error ("...instance of int") is just because you specified '27017'
(a string) instead of 27017
in the configuration dictionary. But even then it should be equivalent to the first, simpler configuration.
这篇关于Django - MongoDB:(无法连接到localhost:27017)连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!