Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

html - How do I send email through button click in django?

I am a beginner in Django. I can not go to the view via ajax code. I have coded it at the button click. This code was written to send an email through button click. In view.py, while code in def error displayed and otherwise if code in class email sent when document load . Email should be sent on button click. Can you help me with that?

user_profile.html

<button class="btn btn-orange" id="btn_delete" onclick="delete_profile1()">Delete</button>

<script>
        function delete_profile1() {
            $.ajax({
                type: 'POST',
                url: '{% url "delete_profile" %}',
                data: { },
                success: function () {
                    toastr.info('Preference Updated Successfully')

                    }
                });
            }
</script>

urls.py

path('delete_profile', delete_profile.as_view(), name='delete_profile'),
   

views.py

class delete_profile(View):
     def post(self, request, *args, **kwargs):
        print("nothing")
        template = loader.get_template("frontend/subscription-start.html")
        email_content = "deletion confirmation"
        send_mail(
            'No Dowry Marriage - Subscription',
            email_content,
            '[email protected]',
            [[email protected]],
            html_message=email_content,
            fail_silently=False
        )

    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First, fix [[email protected]] to ['[email protected]'].

And then, please read the following documents and try to solve the ajax CSRF problem well.

https://docs.djangoproject.com/en/3.1/ref/csrf/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...