[Fixed]-Django Celery send register email do not work

25👍

Celery need to serialize the arguments for a task. Here, user is not serializable, but you can replace it with its ID:

In tasks.py:

from __future__ import absolute_import

from celery.decorators import task
from django.contrib.auth import get_user_model

@task()
def user_send_activation_email(user_id):
    user = get_user_model().objects.get(pk=user_id)
    user.send_activation_email()

Then call it from views.py using:

user_send_activation_email.delay(user_id=user.pk)

8👍

see setting-task_serializer, you can set CELERY_TASK_SERIALIZER = ‘pickle’ in celery conf.

Leave a comment