Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 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 Reply

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...