Flask extensions 汇总
Flask 的扩张结构是在诞生的时候就确定了的。存在各种各样好用的扩张。
这里整理了一些常用的扩张:
1 Flask-script
给flask提供命令行选项,可以在shell里进行调试,测试工作。
pip install flask-scripts
from flask.ext.script import Manager
manager = Manager(app)
manager.run()
python test.py —help
python test.py shell
python test.py runserver -h 0.0.0.0 -p 5000
2 Flask-Bootstrap
pip install flask-bootstrap
from flask.ext.bootstrap import Bootstrap
bootstrap = Bootstrap(app)
user.html
3 Flask-Moment 时间日期本地格式化
pip install flask-moment
from flask.ext.moment import Moment
moment = Moment(app)
index.html
4 Flask-WTF Form表单
pip install falsk-wtf
Form Classes 继承自Form
from flask.ext.wtf import Form
from wtforms import StringField,SubmitField
from wtform.validators import Rrquired
class NameForm(Form):
name = StringField(‘What is your name?’,validators=[Required()])
submit = SubmitField(‘Submit’)
StringField
TextAreaField
PasswordField
HiddenField
DateField
DateTimeField
IntegerField
DecimalField
FloatField
BooleanField
RadioField
SelectField
SelectMultipleField
FielField
SubmitField
FormField
FieldList
5 数据库
pip install flask-sqlalchemy
MySQL mysql://username:password@hostname/database
2 Login
3 Form