我使用命令安装了Celery和RabbitMQ:
def classify_image(request):
if request.method == 'POST' and request.FILES['test_image']:
test_image = request.FILES['test_image']
test_image = cv2.imread(test_image)
test_image = cv2.resize(test_image, (128, 128))
test_image = np.array(test_image)
test_image = test_image.astype('float32')
test_image /= 255
print(test_image.shape)
test_image = np.expand_dims(test_image, axis=0)
pred = model.predict_classes(test_image)
print(pred)
return JsonResponse(pred, safe=False)
和pip install celery
。
芹菜不起作用;我收到这个错误:
sudo apt-get install rabbitmq
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last):
File "/home/morilon/dj/shop/lib/python3.5/site-
packages/celery/app/utils.py", line 361, in find_app
found = sym.app
AttributeError: module 'myshop' has no attribute 'app'
我不明白该怎么办?
tasks.py
Traceback (most recent call last):
File "/home/morilon/dj/shop/bin/celery", line 11, in <module>
sys.exit(main())
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/__main__.py", line 14, in main
_main()
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/bin/celery.py", line 326, in main
cmd.execute_from_commandline(argv)
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/bin/base.py", line 279, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/bin/base.py", line 481, in setup_app_from_commandline
self.app = self.find_app(app)
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/bin/base.py", line 503, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/app/utils.py", line 366, in find_app
found = sym.celery
AttributeError: module 'myshop' has no attribute 'celery'
celery.py
from celery import task
from django.core.mail import send_mail
from .models import Order
@task
def order_created(order_id):
"""
Task to send an e-mail notification when an order is successfully created.
"""
order = Order.objects.get(id=order_id)
subject = 'Order nr. {}'.format(order.id)
message = 'Dear {},\n\nYou have successfully placed an order. Your order id is {}.'.format(order.first_name,
order.id)
mail_sent = send_mail(subject, message, 'admin@myshop.com', [order.email])
return mail_sent
初始化的.py
<。>从.celery导入应用程序as celery_appGitHub上的这个项目https://github.com/Loctarogar/Django-by-Example