I am using apache2 and gunicorn to deploy my flask app, but whenever I use redirect
method. it's redirecting to 127.0.0.1
.
@module.route("/login", methods=["GET", "POST"])
def u():
if request.method == "GET":
return render_template("admin/login.html")
username = request.form.get("username")
password = request.form.get("password")
for user in users:
if username == user["username"] and password == user["password"]:
session["user"] = user
return redirect(url_for("admin.stories", num=1))
return redirect(url_for("admin.u"))
as you can see when wrong username or password entered I am redirecting to itself, when the redirect happen, its going to https://127.0.0.1/admin/login
/etc/systemd/system/app.service
[Unit]
Description=Gunicorn instance to serve flask application
After=network.target
[Service]
User=anyms
Group=www-data
WorkingDirectory=/home/anyms/src/
Environment="PATH=/home/anyms/venv/bin"
ExecStart=/home/anyms/venv/bin/gunicorn --config gunicorn_config.py wsgi:app
[Install]
WantedBy=multi-user.target
/etc/apache2/sites-available/app.conf
<VirtualHost *:80>
ServerAdmin anyms@ubuntu
ErrorLog ${APACHE_LOG_DIR}/flask-error.log
CustomLog ${APACHE_LOG_DIR}/flask-access.log combined
<Location />
ProxyPass unix:/home/anyms/src/app.sock|http://127.0.0.1/
ProxyPassReverse unix:/home/anyms/src/app.sock|http://127.0.0.1/
</Location>
</VirtualHost>
question from:
https://stackoverflow.com/questions/65951531/flask-redirect-method-redirecting-to-localhost 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…