from __future__ import print_function # In python 2.7 import sys @app.route('/button/') def button_clicked(): print('Hello world!', file=sys.stderr) return redirect('/')
Here is what the above code is Doing:
1. We’re using the @app.route decorator to tell Flask what URL should trigger our function.
2. When the user goes to the URL /button/, the function button_clicked() is run.
3. The function button_clicked() prints ‘Hello world!’ to the console, and then redirects the user back to the home page.