gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
django4.0 drf 异步任务接口
- User
django4.0 drf 异步任务接口
- Assistant
在Django Rest Framework (DRF) 中创建异步任务接口有多种方法,这里介绍其中一种常见的方法使用 Celery 异步执行任务。
- 安装所需的包:
codepip install django-celery-results- 在settings.py 文件中配置 Celery:
python# settings.py INSTALLED_APPS = [ ... 'django_celery_results', ... ] CELERY_BROKER_URL = 'amqp://localhost' CELERY_RESULT_BACKEND = 'django-db'- 创建一个新的 Celery 实例:
python