Код:
from flask import Flask, request, render_template, redirect, make_response
app = Flask("app")
@app.route("/")
def _login():
return render_template("login.html")
@app.route("/login", methods=['get', 'post'])
def _redirector():
if request.method == "POST":
user_id = request.form["name"] # Выбераем из формы user_id
resp = make_response()
resp.set_cookie('username', user_id)
return redirect("/chat")
else:
return "Error"
@app.route("/chat")
def _chat():
with open("db/lastauthor.txt", "r") as file:
author = file.read()
with open("db/lastmsg.txt", "r") as file:
content = file.read()
return render_template("chat.html", author=author, content = content)
@app.route("/send", methods=["get","post"])
def _send():
if request.method == "POST":
content = request.form["content"]
else:
return "error"
with open("db/lastmsg.txt", "w") as file:
file.write(content)
with open("db/lastauthor.txt", "w") as file:
file.write(request.cookies.get('username'))
return render_template("back.html")
app.run(host="0.0.0.0", port=8080)
При заходе на начальный сайт, я ввожу никнейм, и после нажатия Enter выдаёт это:
(p.s. После создания куки по документаций, эта ошибка начала появляться)