i created simple chat room application using python flask and socket io now i wanna connect to mysql database how it possible.
You can use a library like SQLAlchemy.
from flask import Flask, render_template from flask_socketio import SocketIO, emit import os app = Flask(__name__) app.config['secretKey'] = os.environ['SECRET_KEY'] socketio = SocketIO(app) @app.route( '/' ) def hello(): ''' :return : return the renderedvalue of HTML ''' return render_template( './ChatApp.html' ) def messageRecived(): ''' :return : return the value message Recevied ''' print( 'message was received!!!' ) @socketio.on( 'my event' ) def handle_my_custom_event( json ): ''' :return : return the message ''' print( 'recived my event: ' + str( json ) ) socketio.emit( 'my response', json, callback=messageRecived ) if __name__ == '__main__': socketio.run( app, debug = True )
how to implement could you add something
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (
</>) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
I have a Flask - SQLAlchemy example here https://github.com/stribny/flask-api-quickstart.
You can examine the source code, the dependencies and how the project works. Then you should be able to implement it in your solution.