My app keeps sending GET although I specified POST

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:

<form method="post" action="/admin/read-api-key">
  <label for="username">Username for API key: </label>
  <input type="text" required name="username">
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):
  def decorated(*args, **kwargs):
    if not in admins:
      return "This page is restricted to admins."
    return f(*args, **kwargs)
  return decorated

@app.route('/admin/api-key', methods=["GET"])
def addAPIKey():
  return render_template("api-key.html")

@app.route('/admin/read-api-key', methods=["POST"])
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)

...'', port=81)
1 Like

Nevermind it works now

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.