【发布时间】:2020-10-15 21:09:33
【问题描述】:
我的 blog.models 正在使用:
from django.contrib.auth.models import User
该模型是从我每小时作为任务运行的脚本中调用的。这是我看到的错误:
Traceback (most recent call last):
File "/home/redinv/src/cron.py", line 8, in <module>
from blog.models import ImagePost, MyPost, ScheduledPost
File "/home/redinv/src/blog/models.py", line 3, in <module>
from django.contrib.auth.models import User
File "/usr/lib/python3.8/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/usr/lib/python3.8/site-packages/django/db/models/base.py", line 103, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 252, in get_containing_app_config
self.check_apps_ready()
File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 134, in check_apps_ready
settings.INSTALLED_APPS
File "/usr/lib/python3.8/site-packages/django/conf/__init__.py", line 79, in __getattr__
self._setup(name)
File "/usr/lib/python3.8/site-packages/django/conf/__init__.py", line 60, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
2020-06-25 00:50:25 -- Completed task, took 3.95 seconds, return code was 1.
在我的 INSTALLED_APPS = 下的设置文件中,我已经有了:
'django.contrib.auth',
这段代码当然是在我的机器上本地运行的,我想弄清楚这里有什么问题?
我尝试从两个位置运行该脚本以查看在尝试查找导入文件时是否存在问题:
/home/username/src
/home/username/src/blog
两者的结果相同。
感谢任何帮助,我是 python 的新手。
谢谢
【问题讨论】:
标签: python django scheduled-tasks pythonanywhere