What is the reason why it cannot be redirected after Post data? And I don't report it wrong.

form class:

from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField,BooleanField,SubmitField
from wtforms.validators import DataRequired,Length

class LoginForm(FlaskForm):
    username = StringField(":",validators=[DataRequired()])
    password = PasswordField(":",validators=[DataRequired(),Length(8,128)])
    remember = BooleanField("")
    submit = SubmitField("")

APP routing:

from flask import Flask,render_template,redirect,url_for,flash
from demos.form.forms import LoginForm


app = Flask(__name__)
app.config["SECRET_KEY"] = "fasdfas2342"
app.secret_key = "secret string"

@app.route("/")
def index():
    return "Hello Flask"

@app.route("/login",methods=["GET","POST"])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        flash("welcome home , %s" % username)
        print(username)
        return redirect(url_for("index"))
    return render_template("login.html" , form=form)

template:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>-Henglu</title>
    <link  rel="stylesheet" type="text/css" href="{{ url_for("static",filename="css/login.css") }}" >
    <script  type="text/javascript" src="{{ url_for("static",filename="jQuery/jquery-3.3.1.js") }}"></script>
    <script  type="text/javascript" src="{{ url_for("static",filename="js/login.js") }}"></script>
</head>
<body>
    <div id="body">
        <div id="logo">
            <img src="{{ url_for("static",filename="img/logo.jpg") }}">
        </div>
        <div id="form">
            <form method="post">
                {{ form.csrf_token }}
                {{ form.username.label }}  {{ form.username }}<br>
                {{ form.password.label }}  {{ form.password }}<br><br>
                {{ form.remember }}  {{form.remember.label }}<br><br>
                {{ form.submit }}<br>
            </form>
        </div>
    </div>
</body>
</html>

Post cannot redirect and does not report an error after submitting data?

Jun.06,2022

feels fine


form obviously lacks an action attribute. Post does not specify


Lou Lou. I have encountered the same problem as you. I don't know if you have solved it. You can communicate

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e51db1-4516d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e51db1-4516d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?