Question:
Like the title, my Flask app keeps sending a GET request when submitting the form although I explicitly specified method="post"
in the <form>
tag. What’s the issue here?
Repl link: https://replit.com/@element1010/Chat
<form method="post" action="/admin/read-api-key">
<label for="username">Username for API key: </label>
<input type="text" required name="username">
</form>
from flask import *
...
from replit import db, web
from random import SystemRandom
from string import ascii_letters, digits
app = Flask(__name__)
admins = ["element1010", "Evanisha", "Coder869", "CosmicBear"]
owners = ["element1010"]
if "banned" not in db.keys():
db["banned"] = []
if "bios" not in db.keys():
db["bios"] = {}
if "chat" not in db.keys():
db["chat"] = []
if "themePreferences" not in db.keys():
db["themePreferences"] = {}
if "apiKeys" not in db.keys():
db["apiKeys"] = {}
...
def adminOnly(f):
@wraps(f)
def decorated(*args, **kwargs):
if web.auth.name not in admins:
return "This page is restricted to admins."
return f(*args, **kwargs)
return decorated
@app.route('/admin/api-key', methods=["GET"])
@web.authenticated
@adminOnly
def addAPIKey():
return render_template("api-key.html")
@app.route('/admin/read-api-key', methods=["POST"])
@web.authenticated
@adminOnly
def readAPIKeyAddition():
form = request.form
newKey = ''.join(SystemRandom().choice(ascii_letters + digits) for _ in range(20))
db["apiKeys"][form["username"]] = newKey
return render_template("api-key-success.html", username=form["username"], key=newKey)
...
app.run('0.0.0.0', port=81)