emr_bp=Blueprint("emr",__name__,url_prefix='/emr')
def test():
for i in range(30):
time.sleep(1)
print('start update')
admin = User(
username='admin',
name='超级管理员'
)
admin.set_password('admin')
db.session.add(admin)
db.session.commit()
flash('end....','info')
@emr_bp.route('/',methods=['GET', 'POST'])
def index():
form=EmrSearchForm()
if request.method == 'POST':
t1 = threading.Thread(target=test)
t1.start()
flash(u'提交服务器运行,请稍等...','info')
page=request.args.get('page',1,type=int)
per_page=current_app.config['EMR_CHECK_RECODES_PER_PAGE']
pagination=EmrCheckRecord.query.order_by(EmrCheckRecord.timestamp.desc()).paginate(page,per_page=per_page)
records=pagination.items
return render_template('emr/index.html',form=form,pagination=pagination,records=records)
以上代码在线程中插入一条数据到数据库,不成功。请问要怎么处理?谢谢!