MongoDB 网易新闻实战
![](https://img.haomeiwen.com/i7691822/16a36fc9ac0bb888.png)
![](https://img.haomeiwen.com/i7691822/f18c73c2d7ad358c.png)
1.依赖安装
![](https://img.haomeiwen.com/i7691822/2529a071da127af5.png)
http://flask-mongoengine.readthedocs.io/en/latest/
2.新闻前台
![](https://img.haomeiwen.com/i7691822/db8e7a00c01fb403.png)
![](https://img.haomeiwen.com/i7691822/46707842e7a7ff77.png)
启动访问没问题,flask
![](https://img.haomeiwen.com/i7691822/0fc7fe178423f6b2.png)
然后,新闻的模型,连接数据库。
通过flask-mongoengine
![](https://img.haomeiwen.com/i7691822/25391b51f63de4e7.png)
在MongoDB数据库中插入一些新的数据,
切换到mongo_news数据库,
![](https://img.haomeiwen.com/i7691822/af95becac438800f.png)
![](https://img.haomeiwen.com/i7691822/825d1549509208f0.png)
下面定义模型,新闻,图片是准备好的。
![](https://img.haomeiwen.com/i7691822/9bb7e51ed4888fee.png)
![](https://img.haomeiwen.com/i7691822/b49c67f81dffb7f9.png)
还有一些评论,可以做些扩展,类似学生的分数。
最后制定coolection
![](https://img.haomeiwen.com/i7691822/488c1eafb2f63320.png)
下面做前台的展现,首先引入
![](https://img.haomeiwen.com/i7691822/9225ee3e1219d36b.png)
![](https://img.haomeiwen.com/i7691822/16b65b62b9fd771d.png)
![](https://img.haomeiwen.com/i7691822/c855140165f60274.png)
上面的要修改一下,否则页面的内容都是一样的
![](https://img.haomeiwen.com/i7691822/0c85ca66cb1eaeb4.png)
![](https://img.haomeiwen.com/i7691822/dbed35b6013cf9a2.png)
前台
![](https://img.haomeiwen.com/i7691822/2fbbd9ebdc6ae317.png)
![](https://img.haomeiwen.com/i7691822/e9deb080824c98c9.png)
3.新闻数据的分页
![](https://img.haomeiwen.com/i7691822/da5a1495293d5dec.png)
![](https://img.haomeiwen.com/i7691822/c644197f2f8409d4.png)
![](https://img.haomeiwen.com/i7691822/3e479ed8f52fa32b.png)
![](https://img.haomeiwen.com/i7691822/266c47e8e8e265eb.png)
以下操作,没看,类似。
数据库笔记(1)-简述
数据库笔记(2)- Mysql 基础
数据库笔记(3)-ORM
数据库笔记(4)-网易新闻的实战
数据库笔记(5)- MongoDB基础
数据库笔记(6)- Python 操作MongoDB
数据库笔记(7)- MongoDB ORM
数据库笔记(8)- 网易新闻实战
数据库笔记(9)- Redis 数据库基础
数据库笔记(10)- Python 操作Redis
网友评论