开发者

What's the common way to layout a Django app with Buildout/djangorecipe?

I have a Django app that I've set up using Buildout laid out like so:

/workspace
  /bin
  /src
    /myproject
      settings.py
      /myapp
         views.py
         ...
  bootstrap.py
  buildout.cfg
  setup.py

The issue is that I'd like both myproject.settings and myapp on the python path. I need the myproject.settings on the path so djangorecipe can import it. And I'd like myapp on the path so that I don't have to write import myproject.myapp all the time.

For now I've got both /workspace/src and /workspace/src/myproject in the Python path, but this feels like a hack and practically makes me worried if there might be situations where import some_module might have confusing resolution patterns because I have two directories that are parent-child to each other.

So questions are:

Is there an accepted way to lay thi开发者_如何学Cs out?

Is it actually bad to have a directory and one of its sub-directories in the path?


There is no problem, on import some_module importer will search in each folder specified at sys.path for some_module/__init__.py and some_module.py. Same for import myproject.some_module, it will search for myproject module, then it will try to find in it some_module with same algorithm.

I'm using the same project structure.


If your buildout.cfg includes develop = . and whatever egg your setup.py defines is included as a dependency for your buildout/parts then whatever code path your setup.py defines will be automatically added to sys.path. Just make sure your setup.py includes src as a code directory. One way to do this is with:

setup(name=...
...
      packages=find_packages('src'),
      package_dir = {'':'src'},
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜