[Answered ]-How and where to call a method in a Class based view Django

1πŸ‘

βœ…

It depends on which REST method do you want to call it. If you are using simple GET, then call it in get() like this:

class VerifyCode(FormView):

    template_name = "account/verify.html"
    form_class = VerifyForm

    def random_code(self):
        #random_code generator
        return random_code

    def send_email(self):
        #code to send email

    def get(self, request, *args, **kwargs):
        ...
        self.random_code()
        self.send_email()
        return super().get(request, *args, **kwargs)

In similar way in post() for POST method.

Another thing is you can send emails directly with Django. I do that and it’s pretty simple. Check this DOCS. You can post another question about that if you have something.

πŸ‘€NixonSparrow

Leave a comment