當我在我的應用中做./manage.py process_email
時,我得到了ImportError: No module named commands.process_email
。django命令找不到命令模塊
我的目錄佈局是:
./
├── __init__.py
├── admin.py
├── forms.py
├── management
│ ├── __init__.py
│ └── commands
│ ├── __init.py__
│ └── process_email.py
├── models.py
├── views.py
的process_email命令的來源是:
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from website.event.models import Event
class Command(BaseCommand):
def handle(self, *args, **options):
process_email()
def process_email():
print "processing email"
,我得到的錯誤:
(website.com)[email protected]cBook ~/code/website.com/website $ > ./manage.py process_email
Traceback (most recent call last):
File "./manage.py", line 14, in <module>
execute_manager(settings)
File "/Users/kings/code/website.com/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Users/kings/code/website.com/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/kings/code/website.com/lib/python2.6/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/kings/code/website.com/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/kings/code/website.com/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named commands.process_email
當我做./manage.py
它在「可用子命令:」中顯示process_email
。這告訴我process_email.py被manage.py看到。另外init .py是空的(我認爲它不重要,但只是供參考)。
你好,歡迎來到SO。只需一個指針 - 不用擔心使用pastebin,歡迎您將代碼/目錄佈局放在這裏(實際上它可以幫助我們,如果你這樣做的話)。 – 2012-02-11 19:45:26
作爲一個警告,Django使用imp.find_module不尊重壓縮的雞蛋:http://stackoverflow.com/questions/28962344/imp-find-module-which-supports-zipped-eggs – benjaoming 2015-04-06 14:12:15