提前致谢,我正在尝试让我对芹菜有点熟悉我无法解决我的问题,已经 4 个小时了我试图找出问题所在但我无法分辨。今天早上一切正常,但现在我在提交表格时面临无限加载。首先,我在 arch 上并使用每个包的最新版本,这是我从终端获得的代码和消息:配置 :演示/设置/base.py :INSTALLED_APPS = ['users.apps.UsersConfig','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','core','books','django_celery_results',] CELERY_RESULT_BACKEND = 'django-db' CELERY_BROKER_URL = f'redis://{config("REDIS_HOST")}:{config("REDIS_PORT")}/{config("REDIS_CELERY_DB")}'DATABASES = {'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db_celery__.sqlite3'),}}环境:REDIS_HOST=localhostREDIS_PORT=6379REDIS_CELERY_DB=0我的模特书籍/模型:from django.db import modelsfrom PIL import Imagefrom django import formsfrom demo import tasksdef resize_model(booquin): img = Image.open(bouquin.cover.path) if img.height > 300 or img.width > 300: output_size = (300, 300) img.thumbnail(output_size) img.save(bouquin.cover.path) bouquin.save()class Bouquin(models.Model): titre = models.CharField(max_length=200) cover = models.ImageField(upload_to="cover")def __str__(self): return self.titre class Bouquin_Form(forms.ModelForm): def save(self, commit=True): book = super().save(commit) tasks.resize_book_celery.apply_async((book.id,)) return book class Meta: model = Bouquin fields = ["titre", "cover"]我的 demo/tasks.py(我在同一个文件中混合了模型和表单,因为它只是为了测试目的)from celery import shared_taskfrom books import models@shared_taskdef resize_book_celery(book_id: int): models.resize_model(models.Bouquin.objects.get(id=book_id))我的演示/celery.py:from __future__ import absolute_import, unicode_literalsimport osfrom celery import Celery
3 回答

慕虎7371278
TA贡献1802条经验 获得超4个赞
要删除所有 Redis 数据库的所有数据/键,请使用 FLUSHALL 命令。打开终端并输入
redis-cli FLUSHALL
我认为这个问题是针对redis的。

潇湘沐
TA贡献1816条经验 获得超6个赞
我已经用这样的超基本功能进行了测试,以查看:
@task
def time_celery(x):
return x ** 2
def multiplication_view(请求):
result = time_celery.delay(2)
context = {"result": result}
return render(request, "demo/multiplications.html", context)
我得到了同样的无休止的加载,所以我认为 redis 肯定有问题,我想我要把我的电脑恢复到今天早上的状态,throw rsync

心有法竹
TA贡献1866条经验 获得超5个赞
切换到 rabbitmq,它似乎可以完美地工作,CELERY_BROKER_URL = 'amqp://localhost' + 启用服务器,如此处解释https://wiki.archlinux.org/index.php/RabbitMQ#Installation
添加回答
举报
0/150
提交
取消