Speed up development with full-stack environments for every branch.

Learn More

How to create a catch all route using Flask [Python]

257 Runs 2915 Views 602 Copies
Saved

Saved

mmolina 24

mmolina
published 4 years ago

from flask import Flask

# Initialize the Flask application
app = Flask(__name__)

# With these routes setup we are catching *any* possible URL/request.
# The root URL/domain for the app (/) is catched by the first route
# While the second route using the path placeholder will catch any 
# route like /login, /logout, or even /foo/bar.
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catchall(path):
  return "Hello! You requested: /%s" % path

if __name__ == '__main__':
	app.run( 
        host="0.0.0.0",
        port=int("80")
  )
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).