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
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…