MongoEngine 中文文档 系列教程 User Guide( 五)
2015-10-09 17:09
741 查看
先很简单的创建一个django的工程(具体不说django),然后弄个小app或者随便哪里写个view就好了.然后我用了几步就确定它可以正常使用了.
首先修改settings.py,原来DATABASES完全不用去管它了,全部设为空串就好,然后在文件里加上下面的内容(这里的连接方式可以自行更换,比如换成url连接的,这里假设是使用本地的mongodb数据库,并且mongodb都是使用的默认配置)
python
在models.py里随便写个模型,这里要用到mongoengine的一些内容
python
在某个views.py里随便哪里写点逻辑,添加条数据而已(两种方式都可以填数据)
python
然后就可以看看数据输出啦
python
好吧,如果顺利就应该可以看到console输出的结果,很给力.当然在mongo中可以查到如下结果
python
挺好玩的.最重要的是它支持sessions,支持Userauthentication,还可以使用gridfs做文件存储,具体可以在这里查到.
到这里就可以在django中使用mongoengine了,其他的数据库操作方式都是mongoengineAPI的用法。
mongoengine文档:http://docs.mongoengine.org/en/latest/index.html
首先修改settings.py,原来DATABASES完全不用去管它了,全部设为空串就好,然后在文件里加上下面的内容(这里的连接方式可以自行更换,比如换成url连接的,这里假设是使用本地的mongodb数据库,并且mongodb都是使用的默认配置)
python
1 2 | frommongoengineimportconnect connect('DB_NAME') |
python
1 2 3 4 5 | frommongoengineimportDocument classTestModel(Document): test_key=StringField(required=True) test_value=StringField(max_length=50) |
python
1 2 3 4 | fromapp.modelsimportTestModel entry=TestModel(test_key='arthur') entry.test_value='Wang' entry.save() |
python
1 2 | forentryinTestModel.objects: printentry.test_key |
python
1 2 | db.testmodel.find() {"_id":ObjectId("4d34267f7ecfdb3b7c000000"),"test_key":"arthur","test_value":"Wang","_types":["TestModel"],"_cls":"TestModel"} |
到这里就可以在django中使用mongoengine了,其他的数据库操作方式都是mongoengineAPI的用法。
mongoengine文档:
相关文章推荐
- MongoEngine 中文文档 系列教程 User Guide( 四)
- MongoEngine 中文文档 系列教程 User Guide( 三)
- MongoEngine 中文文档 系列教程 User Guide( 二)
- MongoEngine 中文文档 系列教程 User Guide( 一)
- ***Xcode Interface Builder或Storyboard中可建立那两种连接?
- iOS开发-------滚动视图(UIScrollView)并实现循环滚动
- iOS开发 手势识别UIGestureRecognizer
- 使用requireJS,backboneJS,和underscoreJS完成自定义模板封装
- RPC和Message Queue对比
- UIButton在不同状态下显示不同背景色
- configure: error: GRUB requires a working absolute objcopy; upgrade your binutils 解决方法
- UINavigationController使用之手动添加UIBarButtonItem
- 【jmeter】Jmeter启动GUI界面出错
- Java --- AbstractQueuedSynchronizer
- UESTC 87 Easy Problem With Numbers 线段树区间更新 逆元 分解质因数
- Guide: Solr performance tuning--转载
- ios上 更改 状态栏(UIStatusBar)的颜色
- 导航控制器UINavigationController
- Android UI框架基本概念
- UIButton中的三个UIEdgeInsets属性(二)