Answer the question
In order to leave comments, you need to log in
Why does redirect fail?
The code:
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)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question