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
AJAS KM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.