- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 django 1.10.5 和 celery 4.0.2。我有这样的结构。
-proj
-application
__init__.py
celery.py
celery_conf.py
settings.py
tasks.py
urls.py
wsgi.py
-extuser (application with extended UserModel)
-pages
-migrations
-templates
__init__.py
admin.py
apps.py
forms.py
models.py
tasks.py
tests.py
views.py
celery -A application worker -l INFO -B
Traceback (most recent call last):
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/bin/celery", line 11, in <module>
sys.exit(main())
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/__main__.py", line 14, in main
_main()
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/bin/celery.py", line 326, in main
cmd.execute_from_commandline(argv)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/bin/base.py", line 281, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/bin/celery.py", line 480, in handle_argv
return self.execute(command, argv)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/bin/celery.py", line 412, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/bin/worker.py", line 221, in run_from_argv
return self(*args, **options)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/bin/base.py", line 244, in __call__
ret = self.run(*args, **kwargs)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/bin/worker.py", line 255, in run
**kwargs)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/worker/worker.py", line 94, in __init__
self.app.loader.init_worker()
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/loaders/base.py", line 116, in init_worker
self.import_default_modules()
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/loaders/base.py", line 111, in import_default_modules
return [self.import_task_module(m) for m in self.default_modules]
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/loaders/base.py", line 97, in import_task_module
return self.import_from_cwd(module)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/loaders/base.py", line 106, in import_from_cwd
package=package,
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/celery/loaders/base.py", line 100, in import_module
return importlib.import_module(module, package=package)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/src/pages/tasks.py", line 4, in <module>
from extuser.models import UserLinksArchive
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/src/extuser/models.py", line 5, in <module>
from django.contrib.auth.models import AbstractBaseUser
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/django/db/models/base.py", line 105, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 237, in get_containing_app_config
self.check_apps_ready()
File "/home/dmitriy/MyEnv/DjangoProjects/sPrint/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
from __future__ import absolute_import, unicode_literals
from application.celery import app
from extuser.models import UserLinksArchive
@app.task
def link_destroy_task(link_id):
link = UserLinksArchive.objects.get(id=link_id)
link.delete()
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.models import BaseUserManager
from django.core.validators import MinValueValidator, MinLengthValidator
from django.db import models
class MyUserManager(BaseUserManager):
def create_user(self, username, password=None, **extra_fields):
if not username:
raise ValueError(u'No user')
user = self.model(username=username)
if password:
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, username, password):
user = self.create_user(username, password)
user.is_admin = True
user.is_superuser = True
user.save(using=self._db)
return user
class ExtUser(AbstractBaseUser, PermissionsMixin):
username = models.CharField(
max_length=255,
null=False,
unique=True,
validators=[MinLengthValidator(6)]
)
balance = models.FloatField(
default=0.0,
validators=[MinValueValidator(0.0)]
)
is_active = models.BooleanField(
default=True
)
is_admin = models.BooleanField(
default=False
)
def get_full_name(self):
return self.username
@property
def is_staff(self):
return self.is_admin
def get_short_name(self):
return self.username
def __str__(self):
return self.username
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = []
objects = MyUserManager()
class Meta:
db_table = 'auth_user'
LINKTYPE = (
('p', 'Password restore'),
('o', 'Other'),
)
class UserLinksArchive(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
default=1
)
hash = models.CharField(
max_length=32,
default=None,
unique=True
)
created_at = models.DateTimeField(
auto_now_add=True
)
type = models.CharField(
max_length=1,
default='o',
choices=LINKTYPE
)
#application/celery.py
# coding=utf-8
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
app = Celery('application')
# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('application.celery_conf', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
#application/celery_conf.py
# CELERY SETTINGS ALARMA
from django.conf import settings
CELERY_IMPORTS = ("application.tasks", "pages.tasks")
CELERY_BROKER_BACKEND = 'redis'
CELERY_BROKER_URL = settings.REDIS_URL
CELERY_RESULT_BACKEND = settings.REDIS_URL
CELERY_TASK_RESULT_EXPIRES = 60 * 60 * 24
CELERY_TIMEZONE = 'Europe/Moscow'
最佳答案
如果您在 tasks.py 的方法中导入 UserLinksArchive,则可以解决此问题
像这样的东西:
@app.task
def link_destroy_task(link_id):
from extuser.models import UserLinksArchive
link = UserLinksArchive.objects.get(id=link_id)
link.delete()
关于django - 为什么当我尝试在 celery 任务中使用模型时,django 会引发 "Apps aren' t 已加载”错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42249088/
我正在使用 SharePoint Online 并使用 Windows Azure 托管访问 SPO 的进程。 我们已将启动任务添加到 Azure 角色以安装 http://www.microsoft
我有一个函数,它获取包含时间的源文件(csv 文件),读取它,然后按顺序对行进行排序并将它们写入目标文件中。但是,如果源 csv 文件不存在,我需要引发 FileNotFoundError。我之前曾引
我试图在目录不存在时引发错误,然后再打开该目录中的文件。根据this response我应该为我的问题使用最具体的异常构造函数,我认为它是 NotADirectoryError。但是运行下面的代码我得
在编码/开发生命的一天或另一天,我们确实遇到了这个特殊的情况,这是最常见的异常(exception)之一。我的问题是关于的而不是。为什么(我知道当我们尝试访问实际上指向null的引用变量的属性时会引发
我想知道在 python 中是否可以在一个 except block 中引发异常并在稍后的 except block 中捕获它。我相信其他一些语言默认会这样做。 这是它的样子" try: som
我有以下代码: br = mechanize.Browser() br._factory.is_html = True br.form = mechanize._form.ParseString(''
我刚刚发现,如果您有一个引发 TOO_MANY_ROWS 异常的 SELECT INTO,该变量仍会从查询检索到的第一条记录中分配值。这是预期的行为吗? 这是我的例子: for co in my_cu
当 SSH 显示 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! 我知道当您重新安装远程服务器时会发生这种情况,但我尝试列出 其他原因 . 我知道如何
我有一个枚举和一个 EnumMap . 我将 map 放入一个类中以隐藏“字节”值。所以我有一个set(Parameter, int)和set(Parameter, boolean)方法。 publi
在什么情况下会redis-py引发以下 AttributeError 异常? redis-py 不是设计来引发仅基于 redis.exceptions.RedisError 的异常吗? 什么是合理的处
可悲的是,对此异常的引用通常具有异国情调,并且可能发生在您例如通过 Assembly.GetTypes() 枚举类型- 举个例子,它发生在我们的一个部署上,但同一组程序集在集成服务器上运行良好。 为了
我正在为 Android 下的特定平板电脑克隆一个存储库并获取源代码,我必须执行一个 python 脚本。当我执行它时,我收到此错误消息: Traceback (most recent call la
首先,执行此操作(在运行 4.4.2 的 Nexus 5 上测试): 将 PRIORITY_LOW 通知传递给 Service.startForeground()。 观察通知不显示在状态栏中。 使用相
我尝试使用 AppEngine 的 python 模块 api 来获取使用基本缩放的模块的实例数。在我模块的 yaml 文件中,我明确设置了 max_instances 参数。我希望 get_num_
当我如下运行我的 spark python 代码时: import pyspark conf = (pyspark.SparkConf() .setMaster("local")
在我的系统上,一段适用于 Python 2 的代码不适用于 Python 3。 f = open("plotwidget.svg") svgData = f.read() xml_stream = Q
我是 PHP 和 SQL 的新手,但我正在创建一个登录系统。我遇到的问题是: You have an error in your SQL syntax; check the manual that c
我有一个使用 ebaysdk 库的 python 代码,当我运行代码并输入关键字进行搜索时,我得到了这个错误。 Traceback (most recent call last): File "eba
当我将表单数据发送到我的 Flask 应用程序时,出现以下错误。它说它将使用 UTF-8 编码,但语言环境已经是 UTF-8。这个错误是什么意思? /home/.virtualenvs/project
在python2.7中,跟随pympler example : from anotherfile import somefunction, somecustomclass from os import
我是一名优秀的程序员,十分优秀!