开发者

Where should I store libraries in a good Django project structure?

In one of the apps of my Django site I require a third-party module/library. I've been reading up on how a good Django project should be structured but it doesn't mention much about storing libraries. My current project is structured like so:

urls.py
manage.py
settings.py
apps
    app1
        views.py
        models.py
        manager.py
        tests.py
    app2
        ...
        ...
        ...
        ...

Should a create a directory at the top-level named libs and dump it there or should I create a libs directory under the specific app folder that I'll be using this in?

Another thing was that when I code Django, I try and keep my views, models and managers very light. If some complex stuff is needed, I create a class/module and dump stuff there. Should I put this in the specific app folder that I'll be using this in or should this go to libs folder as well? I often have a helpers.py file in my apps but I use that for generally storing quite s开发者_JS百科mall and simple helper functions.

One could obviously put the library anywhere. It's all the same to Python but not necessarily the right way to go about this.

Thanks.


If this is a third-party library, it shouldn't be kept in your source code at all.

If you use virtualenv, you get a complete environment that you can install libraries in specifically for that project. Plus, in conjunction with pip, you can set up a requirements.txt file which specifies all the libraries you need to run the project, and installs them in one go when you start on a new machine, or deploy to production.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜