Django Installed Apps Location

前端 未结 3 2144
野性不改
野性不改 2020-12-31 04:04

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

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 04:46

    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

提交回复
热议问题