Let’s go ahead and create a new route in our Flask project.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
@app.route('/contact')
In this line of code, inside the parenthesis, we define the URL with the name ‘/contact’. If someone goes to the URL “http://127.0.0.1:5000/contact“, then it would run this function:
def about():
return 'This is the contact page.'
Now, if we go to the browser and visit the URL “http://127.0.0.1:5000/contact“, you will see that this page displays the text which we wrote earlier in the code.
Here is the full Code:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route('/contact')
def contact_page():
return 'here is the contact page'
if __name__ == '__main__':
app.run()