设置Django和mongodb [英] Setting up Django and mongodb

查看:53
本文介绍了设置Django和mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django 1.9,并且尝试连接到MongoDB数据库来存储数据.我用谷歌搜索,但没有找到任何使用MongoDB数据库设置django的教程.

I am using Django 1.9 and I trying to connect to MongoDB database to store the data. I googled but I did not find any tutorial to setup the django with the MongoDB database.

任何人都可以向我提供使用Django设置mogndb db数据库的教程吗?

Can anyone please provide me tutorial to setup the mogndb db database with the django?

推荐答案

安装:- 要进行冲泡,请在终端中粘贴以下命令:

Installation:- To get brew, paste the below command in terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

要安装mongodb

To install mongodb

brew tap mongodb/brew
brew install mongodb-community

如果您已经有了mongodb,请跳过以上步骤,冲泡

Skip above steps if you already have mongodb, brew

现在在本地启动mongo:-

Now start the mongo in your local:-

brew services start mongodb-community #this command to start mongoldb

要设置mongoDb与python(django)的连接,请使用mongoengine或也可以使用pymongo

To set the connection of mongoDb with python(django), use mongoengine or you can use pymongo also

pip install mongoengine  # to install mongoengine

现在,在settings.py文件中(在django项目中)-

now, in settings.py file (inside django project)-

from mongoengine import connect
connect(‘database name’) # or connect('project1', username='webapp', password='pwd123', authentication_source='admin')

现在,django与mongodatabase连接了.

Now, django is connected with mongodatabase.

这篇关于设置Django和mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆