gpt4 book ai didi

linux - 为什么将 export DJANGO_SETTINGS_MODULE ='myproject.settings' 添加到 bashrc 不再起作用?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:28:39 24 4
gpt4 key购买 nike

我有一个在 Linux 机器 (Debian) 上运行的 Django 应用程序。在过去的一段时间里,该应用程序运行完美。最近我需要在 celery 任务开始挂起并且清除任务没有达到预期效果后重新启动机器。当我现在尝试使用

开始 celery 时
sudo celery -A myapp.tasks worker -Ofair 

我看到了以下回溯

Traceback (most recent call last):
File "/usr/local/bin/celery", line 9, in <module>
load_entry_point('celery==3.1.11', 'console_scripts', 'celery')()
File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 30, in main
main()
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 769, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 304, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 464, in setup_app_from_commandline
self.app = self.find_app(app)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 484, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/usr/local/lib/python2.7/dist-packages/celery/app/utils.py", line 225, in find_app
sym = imp(app)
File "/usr/local/lib/python2.7/dist-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/this/gce_app/myapp/tasks.py", line 8, in <module>
from django.views.decorators.csrf import csrf_exempt
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py", line 1, in <module>
from django.middleware.csrf import CsrfViewMiddleware, get_token
File "/usr/local/lib/python2.7/dist-packages/django/middleware/csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "/usr/local/lib/python2.7/dist-packages/django/utils/cache.py", line 26, in <module>
from django.core.cache import get_cache
File "/usr/local/lib/python2.7/dist-packages/django/core/cache/__init__.py", line 69, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must
either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing set
tings.

我已经将导出添加到 bashrc(最后),这解决了过去的问题,但现在我仍然遇到同样的错误:

sudo nano ~/.bashrc
export DJANGO_SETTINGS_MODULE='myproject.settings'

有没有办法让它再次工作?

最佳答案

您正在使用 sudo 启动 celery,这意味着您以 root 用户身份运行,而不是您为其设置环境变量的用户。不要那样做 - 绝对没有充分的理由用 sudo 运行守护进程。

(与您的问题无关,但您也不应该将 bashrc 编辑为 sudo。)

关于linux - 为什么将 export DJANGO_SETTINGS_MODULE ='myproject.settings' 添加到 bashrc 不再起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25353159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com