I'm having a problem with Flask wherein routes declared in imported modules are not be registered and always result in a 404. I am running the latest version Flask on Python 2.7.
I have the following directory structure:
run.py has the following code:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
import views.home
if __name__ == '__main__':
app.run()
home.py has the following code:
from run import app
@app.route('/test')
def test():
return "test"
When I run run.py
the route declared in home.py
(http://localhost:5000/test) always returns a 404 even though run.py
imports views.home
. The root view (http://localhost:5000) declared in run.py
works fine.
I have written a function that prints out all the registered routes and /test is not in there (get a list of all routes defined in the app).
Any idea why?