9

So in my Django stucture (default setup), my folder structure goes like this:

/mysite
    /mysite
        __init.py
        settings.py
        urls.py
        wsgi.py
    /mymodel
        ...    
    /myapp
        ...
    manage.py

So to access the settings file, wsgi.py is, by default, set to mysite/settings.py. However, Django gave the mysite name to 2 folders, one within the other. So it looks in the top level one, doesn't find it, and raises an error. I tried mysite/mysite/settings.py with the parent mysite's directory in the system path, but that gave the same error.

ImportError: Could not import settings 'mysite.mysite.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named mysite.mysite.settings

To get more info on this error, check How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi?

I'm just wondering why would Django make the default structure so difficult and if renaming stuff is the best way out? Seems it could be sloppy and an error-prone way of doing things. Not sure how many places I'd have to change the name if I did start renaming stuff. Seems dangerous.

Community
  • 1
  • 1
User
  • 23,729
  • 38
  • 124
  • 207

1 Answers1

8

The key point to understand is that the top-level mysite is not a Python package (note that there's no __init__.py). It's just a regular folder that's used for organizational purposes. (That's why mysite.mysite.settings would never work, regardless of the PYTHONPATH.)

All you need to do is make sure that the top-level mysite directory is the only thing from this project on your PYTHONPATH. Once you do that, everything should work the way you expect it to. (If you find the double-naming confusing, though, you certainly can, with some care, rename things.)

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102