I am new to the Flask, and I am stuck in a very basic program, which just greets user with 'Hello' followed by their name. I wrote the code as below:
@app.route('/hello/')
def hello(name):
return "Hello %s"% name
@app.route('/')
def greet():
guest = "Mike"
return redirect(url_for('hello',name=guest))
In this, I want to print "Hello Mike" on the url "localhost:5000/hello"
. However, it gives an error. This error gets resolved by modifying the line @app.route('/hello/')
to @app.route('/hello/<name>')
, but it then means for every different user, it redirects to a different url.
So is there any way that the redirected URL remains the same, i.e. "localhost:5000/hello"
, but the function hello(name)
still receives the argument?