This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2022_Stanislav_Mykhailenko/Lesson_6/Task 1/webserver.py

29 lines
736 B
Python
Raw Normal View History

# Lesson 6 Task 1: web chat
# Author: Stanislav Mykhailenko
# License: Unlicense
2023-01-06 21:35:22 +00:00
from databaseWorker import *
from flask import Flask, render_template, redirect, request
app = Flask("Chat")
prepareDb("messages.db")
@app.route('/')
def index():
rows = getMessages("messages.db")
return render_template("index.html", messages=generateMessagesHTMLTable(rows))
@app.route('/send')
def send():
nickname = request.args.get('nickname')
message = request.args.get('message')
sendMessage("messages.db", nickname, message)
return redirect('/')
@app.route('/getMessagesTable')
def getMessagesTable():
rows = getMessages("messages.db")
return generateMessagesHTMLTable(rows)
app.run(host='0.0.0.0', port=8081)