Flask app does not use routes defined in another module Flask app does not use routes defined in another module flask flask

Flask app does not use routes defined in another module


You have four modules here:

  • __main__, the main script, the file you gave to the Python command to run.
  • config, loaded from the config.py file.
  • views, loaded from the views.py file.
  • app, loaded from app.py when you use import app.

Note that the latter is separate from the first! The initial script is not loaded as app and Python sees it as different. You have two Flask objects, one referenced as __main__.app, the other as app.app.

Create a separate file to be the main entry point for your script; say run.py:

from app import appimport configif __name__ == '__main__':    app.run(host=config.host, port=config.port, debug=config.debug)

and remove the import config line from app.py, as well as the last two lines.

Alternatively (but much uglier), use from __main__ import app in views.py.