Chat room application

i created simple chat room application using python flask and socket io now i wanna connect to mysql database how it possible.

1 Like

You can use a library like SQLAlchemy.

1 Like
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__': app, debug = True )

how to implement could you add something

1 Like

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

You can examine the source code, the dependencies and how the project works. Then you should be able to implement it in your solution.