0

I have some Django project sturcture:

PROJECT
--APPS
----Profile
----...
--PLUGINS
----ENDLESS_PAGINATION
----DJANGO_SUBDOMAINS
----...

And for example: in ENDLESS_PAGINATION models.py file is import:

from endless_pagination import ...

which can't be done.

ImportError: No module named endless_pagination

It only works when I have this structure:

PROJECT
--DJANGO_SUBDOMAINS
--ENDLESS_PAGINATION
--APPS
----Profile
----...

But I prefer the first and don't like change my plugins imports. Please help!

user2721435
  • 151
  • 1
  • 12

1 Answers1

0

You can do this by putting the PLUGINS directory in your PYTHONPATH.

In your settings.py add:

settings.py

import os, sys
PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
sys.path.append(os.path.join(PROJECT_ROOT, 'APPS'))
sys.path.append(os.path.join(PROJECT_ROOT, 'PLUGINS'))

After that, you can refer to modules in apps or plugins without need "apps." or "plugins." prefix.

The PROJECT_ROOT layout is for django 1.4 or newest, if you are using django 1.3 or lowest you will probably do this PROJECT_ROOT = os.path.dirname(__file__).