Created
September 17, 2018 06:08
-
-
Save rupesh2017/8cafd51fbf83fa427c371b43a129d355 to your computer and use it in GitHub Desktop.
chat with redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
from flask import Flask,jsonify,render_template,request | |
from flask_socketio import SocketIO,emit,join_room,leave_room,send | |
from werkzeug import secure_filename | |
app = Flask(__name__) | |
app.config["SECRET_KEY"] = os.getenv("SECRET_KEY") | |
socketio=SocketIO(app) | |
@app.route("/") | |
def index(): | |
return render_template("index.html") | |
@app.route("/chat" ,methods=["POST"]) | |
def chat(): | |
print("running chat") | |
return render_template("chat.html") | |
@socketio.on('join') | |
def on_join(data): | |
username = data['user'] | |
room = data['room'] | |
join_room(room) | |
emit('chat',{'username':username},room=room) | |
print("room has been allocated") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment