I don't understand why this feature in my flask/html webapp doesn't work


Right now when I go to this page, it properly redirects, me, and I can log in properly, and it can properly authenticate me, but when it redirects to /home, it gives me the not logged in page. When I remove this, it doesn’t get the username and leaves it blank. I set the variables to global and there are no errors, but I want to know what’s going on and to fix it, because this took me forever to make lol

Repl link:

The Code:
(Note, site with scrambled letters and numbers has a different link now)

from flask import Flask, redirect, request, render_template
import requests, random

app = Flask('app')
fullyloggedin = 0

username = ''

def home():
  return redirect(

def loggedin():
  if "loggedin" in request.args:
    if request.args.get("loggedin") == 1:
      isloggedin = 1
      isloggedin = 0
    return "This is oauth :/"
  if "username" in request.args:
    username = str(request.args.get("username"))
    fullyloggedin = 1
  elif isloggedin == 1:
    fullyloggedin = 0
    return "Please give username"

    fullyloggedin = 0
    return "Please enter in the correct information"
  if "authkey" in request.args:
    inputtedauthkey = request.args.get("authkey")
    realauthkey = requests.get(
    if int(inputtedauthkey) == int(realauthkey):
      fullyloggedin = 1
        + str(random.randint(0, 99999999999999999999))).json()

      fullyloggedin = 0
      return "Unauthorized Key!"
    fullyloggedin = 0
  if fullyloggedin == 1:

    return redirect("/home")

def homepage():
  global username, fullyloggedin
  if fullyloggedin == 1:
    return render_template("homepage.html", username=username)
    return "Not Logged In :("


def not_found_error(error):
  return "We Couldn't Find That Page :("

app.run(host='', port=8080)

I think the problem is that the request is for each URL. Try logging the information in a db or file instead.


@CoderElijah What do you mean the request is for each url? Just to clarify :slight_smile:

You can’t send requested info from /home to /loggedin or vise versa AFAIK. You can however, send it to a file or db and then get it from there.

1 Like

Oh, alright, good to know! Ill try that and let you know.

Thank you so much it worked!

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