Reputation: 520
I've got two Django apps that will end up sharing a lot of code (both reference an external API and do data manipulation on what that API returns). I'm trying to find out how to properly share code between the two apps.
So far I've been trying to have a third app that's imported by the first two, so my file structure looks something like this:
\MyProject
\app1
__init__.py
views.py
\app2
__init__.py
views.py
\common
__init__.py
myCommonCode.py
But when I try the following from app1 or app2 I don't see myCommonCode.py
import common
print dir(common)
All three apps are included in my INSTALLED_APPS in my settings.py.
I am certain there's something simple I'm missing, I just can't seem to find out what it is. To clarify, I am NOT trying to share the same model at this point, but the same python code for reaching out to an external API.
Upvotes: 1
Views: 83
Reputation: 14369
You don't see a sub-module if you import a package. You have to import it in the
__init__.py
or directly:
from common import myCommonCode
Upvotes: 5