41👍
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:
2👍
As long as your apps are in your PYTHONPATH, everything should work. Try setting that environment variable to the folder containing your apps.
PYTHONPATH="/path/to/your/apps/dir/:$PYTHONPATH"
- [Django]-Django celery task: Newly created model DoesNotExist
- [Django]-Is this the right way to do dependency injection in Django?
- [Django]-Malformed Packet: Django admin nested form can't submit, connection was reset
1👍
Your top-level urls.py
(also named in your settings.py
) must be able to use a simple “import” statement to get your applications.
Does import project.apps.app1.urls
work? If not, then your PYTHONPATH
isn’t set up properly, or you didn’t install your project in Python’s site-packages
directory.
I suggest using the PYTHONPATH
environment variable, instead of installing into site-packages. Django applications (to me, anyway) seem easier to manage when outside site-packages.
We do the following:
-
Django projects go in
/opt/project/
. -
PYTHONPATH
includes/opt/project
. -
Our
settings.py
usesapps.this
andapps.that
(note that theproject
part of the name is part of thePYTHONPATH
, not part of the import.
- [Django]-Django 1.7 – App 'your_app_name' does not have migrations
- [Django]-Django.db.utils.ProgrammingError: relation "bot_trade" does not exist
- [Django]-How to run celery as a daemon in production?