This is my Django app folder structure
|-----tt
| |--settings.py
|
|-----warehouse
| |--models.py
| |--__init__.py
|
|-----dashboard
| |--email_excel_reports.py
|
Inside my email_excel_reports.py
# for ORM query
from warehouse.models import EntryFormLineItem
from django.db.models import Sum
from django.db.models.functions import Coalesce
from django.utils import timezone
line_items = EntryFormLineItem.objects.filter(approved_by__isnull=False, ...
I got this error when I run python email_excel_reports.py
inside dashboard
Traceback (most recent call last):
File "/vagrant/dashboard/email_excel_reports.py", line 11, in <module>
from warehouse.models import EntryFormLineItem
ImportError: No module named 'warehouse'
Bear in mind that when I run the python email_excel_reports.py
I was running gunicorn with nginx, so the django
app is running successfully.
The __init__.py
inside warehouse
default_app_config = 'warehouse.apps.WarehouseConfig'
When I run python manage.py shell
and then type the same lines of code, there was no problem running the code.
How do I get over the error?
RE-OPEN -- WHY?
Simply because the fix was to have python manage.py shell <
placed in front of the python script file and this fix was not available in the supposedly duplicated question's answers.