user623990
user623990

Reputation:

Flask app structure is giving me module headaches

I'm a newcomer to Python and Flask so I may be completely off with my app's organization. Here's what the directory structure looks like:

  + venv
    + bin
    + include
    + lib
    + myapp
      - __init__.py
      + config
        - __init__.py
        - development.py
        - production.py
      + templates
        - layout.html
        (more html files here and directories)
      + db
        - development.db
        - production.db
      + static
        (all my css/js/etc)
      + views
        - __init__.py
        - main.py
      + models
        - __init__.py
        - game.py

Everything has worked so far, until I started working on models. I'm trying to import myapp.models.game and for some reason it doesn't work. Instead it complains saying the myapp module doesn't exist.

Why is this happening and what am I missing? Should I be organizing files in a different way?

Upvotes: 0

Views: 74

Answers (1)

user4298449
user4298449

Reputation:

If you are already inside myapp, try importing just models.game. Also, be sure to make sure there really is an __init__.py in each directory, as you will not be able to import the python module without it.

Upvotes: 1

Related Questions