mongodb+django 怎么配置
1个回答
展开全部
settings.py
import mongoengine
# ...
# DATABASES section should be:
DATABASES = {
'default': {
'ENGINE': '',
},
}
SESSION_ENGINE = 'mongoengine.django.sessions'
_MONGODB_USER = 'db_user'
_MONGODB_PASSWD = 'db_password'
_MONGODB_HOST = 'db_host'
_MONGODB_NAME = 'db_name'
_MONGODB_DATABASE_HOST = \
'mongodb://%s:%s@%s/%s' \
% (_MONGODB_USER, _MONGODB_PASSWD, _MONGODB_HOST, _MONGODB_NAME)
mongoengine.connect(_MONGODB_NAME, host=_MONGODB_DATABASE_HOST)
# ...
AUTHENTICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
)
example of models.py:
from __future__ import unicode_literals
from mongoengine import Document, StringField, IntField, ListField
class Post(Document):
title = StringField()
status = IntField()
tags = ListField()
comments = ListField()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询