0

I have a catch-all route set up in Flask and I want to parse the URL regardless of the length.

from flask import Flask
app = Flask(__name__)
app.route('/')
app.route('/<path:path>')
def main(path=None):
  if path == None:
    return 'foo'
  else:
    return 'bar'
if __name__ == '__main__':
   app.run()

The problem is I'm getting a 404 Not Found error and I don't know why. The url I'm using to test is /hello/world/. Thanks in advance.

davidism
  • 121,510
  • 29
  • 395
  • 339
jacobpadkins
  • 351
  • 3
  • 9
  • 2
    Are you sure the error is raised in the code snippet you provided? `.spit()` returns a list of strings so I assume the error is raised somewhere below the `for` statement in the part of your code you didn't provide. Additionally, you might take a look at this: http://stackoverflow.com/q/15117416/3991125 – albert Dec 25 '15 at 09:39
  • 1
    Please show the full traceback. As albert says, it doesn't seem to be coming from this code. – Daniel Roseman Dec 25 '15 at 09:58

1 Answers1

1

You forgot @ before routing decorators. Change it this way:

@app.route('/')
@app.route('/<path:path>')

and it will work.

Aleksandr Kovalev
  • 3,508
  • 4
  • 34
  • 36