4

谁能看到我在这里做错了什么?无论我尝试什么,我似乎都无法将其设置为正确检测 Django 的设置。在活动 virtualenv 的终端中手动运行时工作正常。

导师

[program:celery_beetlejuice]
command = /home/padraic/.virtualenvs/beetlejuice/bin/python /home/padraic/CodeDev/beetlejuice/beetlejuice_django/manage.py celeryd -B -E -l INFO
directory=/home/padraic/CodeDev/beetlejuice/beetlejuice_django
environment=PYTHONPATH="/home/padraic/CodeDev/beetlejuice/beetlejuice_django", DJANGO_SETTINGS_MODULE="beetlejuice_django.settings"
user = padraic
autostart=true
autorestart=true
stdout_logfile=/home/padraic/CodeDev/beetlejuice/beetlejuice_django/logs/celeryd.log
stderr_logfile=/home/padraic/CodeDev/beetlejuice/beetlejuice_django/logs/celeryd.log
redirect_stderr=true
priority=998
numprocs=1

追溯

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 263, in fetch_command
    app_name = get_commands()[subcommand]
  File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 109, in get_commands
    apps = settings.INSTALLED_APPS
  File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/conf/__init__.py", line 134, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'beetlejuice_django.settings' (Is it on sys.path?): 
4

1 回答 1

4

叹息...找出错误...

所以!我有我的 settings.py 文件,其中包含:

[settings.py]
import os
BEETLEJUICE_STATE = os.environ.get('BTJC_STATE',  None)

if BEETLEJUICE_STATE == 'LOCAL':
    from local_settings import *
elif BEETLEJUICE_STATE == 'DEV':
    from development_settings import *
elif BEETLEJUICE_STATE == 'PROD':
    from production_settings import *
else:
    raise ImportError

<aside>
...这曾经是做事的正确方式(或者我被告知)。我打算改用 Audrey 和 Danny 在Two Scoops of Django中推荐的方式,其要点是:

settings/
    __init__.py
    base.py
    local.py
    test.py
    production.py

...并从现在开始显式调用我的设置文件,例如
python manage.py runserver --settings='settings.production'
...从其中导入base.py并具有所有特定于生产的设置。
</aside>

...并且我在 virtualenvwrapperpostactivate文件中导出了 BTJC_STATE ,除了通过主管运行 celeryd 我没有激活任何东西,从而完全跳过了该文件!这引发了 ImportError 但我没有意识到它是从哪里来的 =(

添加一个解释异常的字符串是一个好主意......显然使用ImproperlyConfigured是提出这个问题的更好方法。因此,通过更改我的 .conf 文件中的以下一行,它开始完美运行。

[program:celery_beetlejuice]
<snip>
environment=BTJC_STATE='LOCAL'
<snip>

所以现在可行,我很高兴,但我需要找到一种设置环境变量(如数据库密码、api 密钥等)的好方法,该方法可以在未激活的使用中的 virtualenv 中很好地工作。

欢迎所有建议,给我发消息,我会用解决方案更新这个=)

于 2013-11-14T11:37:39.903 回答