1
class CreateAccountView(APIView):
    permission_classes = []
    def post(self, request):
        print(request.data)
        email = request.data.get('email')
        if User.objects.filter(email=email).exists():
            return Response({"message": "User with this email already exists"},    status=status.HTTP_203_NON_AUTHORITATIVE_INFORMATION)
        serializer = RegisterSerializer(data=request.data)
        if serializer.is_valid():
            domain = request.get_host()
            **send_verification.delay(email,domain)**
            serializer.save()
            return Response({"message": "Check your email to verify your account"}, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@shared_task(bind=True)
def send_verification(self,email,domain):
    print(email)
    try:
        email_from = settings.EMAIL_HOST_USER
        token = generate_token(email)
        verify_url = f'http://{domain}{reverse("verify_email", args=[token])}'
        subject = 'Verify your email address'
        message = f'Click the link to verify your email: {verify_url}'
        send_mail(subject, message, email_from, [email])
        print(message)
    except Exception as e:
        print(f'Error sending email: {e}')
    print("Done")
    return "Done"

when i was try to send a verification link through celery and pass 2 arguments to the send_verification() function but it always says takes 1 positional argumentt and 3 where given

1
  • Can you post traceback error? Commented Jun 28, 2024 at 20:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.