缘起
寨大呆久了食堂吃个遍,每日吃饭成问题。早就想写个食堂选择器,先前看node.js火试着写一下,但我毕竟不是web🐒,写js这是最痛苦的。近来学用Python后渐渐熟悉语法,便寻思用python重写。
Flask是个python微框架,拿来写我这种小应用是十分合适。
垃圾教程毁我时间
本篇不是flask教程,如何安装等等在此不表。说说我遇到的坑,
储存食堂信息显然要用数据库,为保方便,使用MongoDB。因此使用Flask-PyMongo插件。其中文档有一段:
PyMongo connects to the MongoDB server running on port 27017 on localhost, and assumes a default database name of app.name (i.e. whatever name you pass to Flask). This database is exposed as the db attribute.
You can use db directly in views:
@app.route(’/’) def home_page(): online_users = mongo.db.users.find({‘online’: True}) return render_template(‘index.html’, online_users=online_users)
其中users是mongoDB中数据库的Collection,但在这里看不出是object还是method🌚。直接拿来写总是不成,害我怀疑是插件问题还是数据库问题。
python这种动态语言不标出类型还是有缺陷。
项目源码移步[github](https://github.com/ckyOL/CateteriaSelector-flask)分享文章
生成精美分享图或复制链接,与更多人分享本文。
继续阅读
换条路线
从其他文章中稳定抽取
最后更新于 ,距今已过 3486 天
部分内容可能已过时
评论