如何修复“将数据从flask-socketio事件处理程序传递到Flask-SQLAlchemy”

时间:2019-08-10 18:06:23

标签: python-3.x flask-sqlalchemy flask-socketio

  

我想将事件json数据从 flask-socketio 传递到flask-SQLalchemy

下面是我的代码:

from flask import Flask, render_template

    from flask_socketio import SocketIO, emit

    from flask_sqlalchemy import SQLAlchemy


    @socketio.on( 'my event' )

    def handle_my_custom_event( json ):

     #HOW TO PASS THE VALUE from this event to my database

     #AM i using import json or flask-json and how? any reference

      # usern = History(username=json.user_name)

      # messg = History(message=json.messg)

      # db.session.add(usern)

      # db.session.add(messg)

      # db.session.commit()

      print( 'recived my event: ' + str( json ) )

      socketio.emit( 'my response', json, callback=messageRecived )

这不起作用。我是python烧瓶的新手。请提供任何参考或解释

0 个答案:

没有答案