Exemplo n.º 1
0
def init_db():
    with app.app_context():
        db = connect_db()
        with app.open_resource('schema.sql',
                               mode='r') as f:  # mode='r'只读模式 rb可读,可写
            db.cursor().executescript(f.read())  # 执行sql脚本
        db.commit()  # 提交sql表    commit 后断开连接数据库
Exemplo n.º 2
0
def send_async_email(app, msg, db):
    with app.app_context():
        try:
            r = mail.send(msg)
            if not r:
                status = 0
        except:
            status = -1

    log = {
        'status':status,
        'subject':msg.subject,
        'from':msg.sender,
        'to':list(msg.send_to),
        'date':msg.date,
        'body':msg.body,
        'html':msg.html,
        'msgid':msg.msgId,
        'time':time.time()
    }
    db.email_log.insert(log)
Exemplo n.º 3
0
def send_async_email(app, send):
    with app.app_context():
        mail.send(send)
Exemplo n.º 4
0
from apps import app

if __name__ == '__main__':
    with app.app_context():
        from apps.models import db
        db.create_all()
    app.run()
Exemplo n.º 5
0
# coding: utf-8
from apps import app
from apps.urls import register_url

register_url(app)  # 注册路由,这里是总路由

from middleware.errorhandler import *  # 调用异常捕获类
from middleware.request_handler import *  # 调用请求钩子
app.app_context().push()  # 推送上下文之后,下方中间层才能使用current_app
Exemplo n.º 6
0
def init_db():
    with app.app_context():
        db = connect_db()
        with app.open_resource('schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()
Exemplo n.º 7
0
def select(sql):
    with app.app_context():
        db = get_db()
        db.row_factory = make_dicts
        return query_db(sql)
Exemplo n.º 8
0
def gethistory():
    with app.app_context():
        success = query_db('select * from WEBSHELL', one=False)
        if success:
            return success