Django已安装的应用程序位置 [英] Django Installed Apps Location

查看:187
本文介绍了Django已安装的应用程序位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一位经验丰富的PHP程序员,首次使用Django,我认为这是不可思议的!



我有一个有很多应用程序的项目,所以我想将它们分组到一个应用程序文件夹中。



所以项目的结构是:

  / project / 
/ project / apps /
/ project / apps / app1 /
/ project / apps / app2

然后在Django设置我已经这样说:

  INSTALLED_APPS =(
'project.apps.app1',
'project.apps.app2',

这似乎不起作用?



有关如何将所有应用程序放入seprate文件夹的任何想法,不在项目根?



非常感谢。

解决方案

确保'__init__.py'文件位于您的应用目录中,如果不存在,则不会将其识别为软件包的一部分。



所以每个文件夹她e应该有'__init__.py'文件。 (空是好的)。

  / project / 
/ project / apps /
/ project / apps / app1 /
/ project / apps / app2

然后只要你的根' '文件夹位于您的PYTHONPATH中,您可以从应用程序导入。



以下是有关您的阅读乐趣的python搜索路径的文档:



http:/ /docs.python.org/install/index.html#modifying-python-s-search-path



还有一个很好的简单解释__init__。 py文件用于:



http://effbot.org/pyfaq/what-is-init-py-used-for.htm


I am an experienced PHP programmer using Django for the first time, and I think it is incredible!

I have a project that has a lot of apps, so I wanted to group them in an apps folder.

So the structure of the project is:

/project/
/project/apps/
/project/apps/app1/
/project/apps/app2

Then in Django settings I have put this:

INSTALLED_APPS = (
    'project.apps.app1',
    'project.apps.app2',
)

This does not seem to work?

Any ideas on how you can put all your apps into a seprate folder and not in the project root?

Many thanks.

解决方案

Make sure that the '__init__.py' file is in your apps directory, if it's not there it won't be recognized as part of the package.

So each of the folders here should have '__init__.py' file in it. (empty is fine).

/project/
/project/apps/
/project/apps/app1/
/project/apps/app2

Then as long as your root 'module' folder is in your PYTHONPATH you'll be able to import from your apps.

Here's the documentation regarding the python search path for your reading pleasure:

http://docs.python.org/install/index.html#modifying-python-s-search-path

And a nice simple explanation of what __init__.py file is for:

http://effbot.org/pyfaq/what-is-init-py-used-for.htm

这篇关于Django已安装的应用程序位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆