-1
這是我的Django應用程序的文件夾結構單獨的Python腳本不能找到自定義模塊內的Django
|-----tt
| |--settings.py
|
|-----warehouse
| |--models.py
| |--__init__.py
|
|-----dashboard
| |--email_excel_reports.py
|
裏面我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, ...
當我運行python email_excel_reports.py
內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'
熊記住當我運行python email_excel_reports.py
時,我用nginx運行gunicorn,所以django
應用程序運行成功。
的__init__.py
內部warehouse
default_app_config = 'warehouse.apps.WarehouseConfig'
當我運行python manage.py shell
然後鍵入相同的代碼行,有運行代碼沒有問題。
我該如何克服錯誤?
重新開放 - 爲什麼?
只是因爲修復是要將python manage.py shell <
放置在python腳本文件的前面,並且此修補程序在所謂重複問題的答案中不可用。
有你'warehouse'目錄'__init __。py'文件? – shady
是的,我剛剛將內容添加到問題 –
當您想要在命令行中運行此腳本時,您需要設置django環境。 – shady