Redirecting to another page with button click in Python-flask
Redirecting to another page with click in Python-flask
<a class="dropdown-item" href="{{ url_for('terms') }}"><span
class="item-text">Terms Conditions</span></a>
<div class="dropdown-items-divide-hr"></div>
<a class="dropdown-item" href="{{ url_for('privacy') }}"><span
class="item-text">Privacy Policy</span></a>
Redirect to a URL in Flask
A redirect is used in the Flask class to send the user to a particular URL with the status code. conversely, this status code additionally identifies the issue. When we access a website, our browser sends a request to the server, and the server replies with what is known as the HTTP status code, which is a three-digit number.
Syntax of Redirect in Flask
Syntax: flask.redirect(location,code=302)
Parameters:
- location(str): the location which URL directs to.
- code(int): The status code for Redirect.
- Code: The default code is 302 which means that the move is only temporary.
Return: The response object and redirects the user to another target location with the specified code.
THEN GO TO UR MAIN.PY PAGE :
@app.route('/terms')===> it is the name of file which we have mentioned inside href of above
def terms():====> keep it same as name above
return render_template('terms-conditions.html')====then this page will open when click avovelink:::Terms Conditions - Evolo - StartUp HTML Landing Page Template
@app.route('/privacy') ===> it is the name of file which we have mentioned inside href of above
def privacy()::====> keep it same as name above
return render_template('privacy-policy.html')====then this page will open when clickavove:url_for() Function in Flask
Another method you can use when performing redirects in Flask is the url_for() function URL building. This function accepts the name of the function as the first argument, and the function named user(name) accepts the value through the input URL. It checks whether the received argument matches the ‘admin’ argument or not. If it matches, then the function hello_admin() is called else the hello_guest() is called.
A redirect is used in the Flask class to send the user to a particular URL with the status code. conversely, this status code additionally identifies the issue. When we access a website, our browser sends a request to the server, and the server replies with what is known as the HTTP status code, which is a three-digit number.
Comments
Post a Comment