-2

To whoever downvoted my question because they saw there were related answers. The only related question/answers I saw was about redirecting to a full URL. I want to know how to redirect to another function so I can pass a parameter. PLEASE re-read my issue before jumping to conclusions.

My problem: If the user is directed to /userLogoutGo, I'd like that function to pass the message you see on to the index function and have that function open its template. Please help me see what I'm doing wrong? Thanks!

from flask import Flask, request, render_template, redirect, url_for, session

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
@app.route('/userLogin', methods=['GET', 'POST'])
def index(myParam=''):
    if myParam != '':
        t_message = myParam
    else:
        t_message = "Login or Register"
    return render_template("user_register.html",
                           t_message=t_message,
                           t_js="user_register.js",
                           t_title=t_message,
                           id_user=id_user)
                           
@app.route('/userLogoutGo', methods=['GET', 'POST'])
def userLogoutGo():
    global id_user
    id_user = 0
    a = index("Logged out. Now you can Log In or Register")
ScotterMonkey
  • 1,007
  • 12
  • 25
  • 1
    I think what you want to do is using the redirect function of flask. – mama Aug 26 '20 at 21:25
  • 1
    You can safely use `"Login or Register"` as the default argument instead of `''`, since `str` values are immutable. – chepner Aug 26 '20 at 21:29
  • Seeing error whether I use Flask or flask: ```return Flask.redirect(Flask.url_for('/userLogin')) AttributeError: type object 'Flask' has no attribute 'redirect' ``` ``` return flask.redirect(flask.url_for('/userLogin')) NameError: name 'flask' is not defined``` – ScotterMonkey Aug 26 '20 at 21:50

1 Answers1

1

I think what you want to do is using the redirect function from flask. Then the user will be redirected to the loginurl and the index function will be run.

mama
  • 2,046
  • 1
  • 7
  • 24