Flask常用操作记录

 

sqlAlchemy使用多数据库:

config:

SQLALCHEMY_BINDS = {
        'pg': 'postgresql://user:[email protected]:1988/db',
        'mysql': 'mysql://user:[email protected]:3306/db'
    }

 models:

class pic_search(db.Model):
    __tablename__='table'
    __bind_key__ = 'mysql'
    createtime= db.Column(db.DateTime, nullable=False)

sqlAlchemy 模糊查询+逻辑:

DBSession().query(user).filter(user.u_name.like('%三%')).filter(user.u_name.like('%猫%'))

或者可以用 and_ or_

DBSession().query(user).filter(and_(user.u_name.like('%三%'), user.u_name.like('%猫%')))
street_pic_search.query.filter(or_(street_pic_search.tags.like(w) for w in like_list))

 

flask复选框:

 

Flask常用操作记录_第1张图片

form.py

class SimpleForm(FlaskForm):
    string_of_files = [('价格', '价格'), ('版型', '版型'), ('款式', '款式'), ('面料', '面料'), ('品质', '品质'), ('颜色', '颜色')]
    tag = SelectMultipleField('tag', choices=string_of_files)
    items8 = StringField("UserId", validators=[Length(0, 64)])
    submit = SubmitField('提交')
html


   
   
   

 

 

你可能感兴趣的:(WEB,flask)