I'm working on a project, developing it using flask . I want to link a html page with flask app and whenever the user click on register button of html page , I want that it redirect user to another html page through flask app. How can I do that ?
CodePudding user response:
For example, using Nginx host two flask apps using uwsgi Nginx config
location /otherapp/ { try_files $uri @otherapp; }
location @otherapp {
include uwsgi_params;
uwsgi_pass unix:/tmp/otherapp.sock;
}
location / { try_files $uri @baseapp; }
location @baseapp{
include uwsgi_params;
uwsgi_pass unix:/tmp/baseapp.sock;
}
You can redirect to a page to other app by
@app.route('/')
def test():
return redirect('/otherapp')
CodePudding user response:
I hope I understood your question. You'd like to have a route that takes you to an HTML page and then be able to click a link on that page that will take you to another route.
Here is how you can do that: The first function in app.py
@app.route('/'):
def index():
return render_template("index.html")
Your index.html file may look like this:
<body>
<a href="/register">Register</a>
</body>
The second function in app.py:
@app.route('/register')
def register():
# Ensure the user reached path via GET
if request.method == "GET":
return render_template("another_file.html")
else:
pass # Pass is a Python way to say 'do nothing'
I included a conditional statement in the second function because maybe you'd like the user to register by submitting a form. If you do this, you may want to do different things depending on the request method.