Reputation: 4353
In Django, I used to write populating scripts and put them in the project root directory. For example,
mysite/
mysite/
manage.py
populateA.py
The first few lines of populateA.py
:
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
import django
django.setup()
...
As there are more and more populating scripts, I would like to move them to another package populate
:
mysite/
mysite/
manage.py
populate/
__init__.py
populateA.py
populateB.py
populateC.py
...
However, when I run the populating scripts (python populateA.py
), I got the error message: ImportError: No module named 'mysite'
. How to properly set the path for DJANGO_SETTINGS_MODULE
?
Upvotes: 0
Views: 138
Reputation: 798764
Since populate
is already a module, run its submodules.
python -m populate.populateA
Upvotes: 1