this my view.py:
from django.contrib import messages
from django.core.mail import send_mail
from django.shortcuts import redirect
from django.http import HttpResponse
def sendmail(request):
if request.method == 'GET':
send_mail('this is subject',
'Hello alex',
"mysite.com <orders@mysite.com>",
['reciver_email@gmail.com'],
fail_silently=False)
return HttpResponse('ok')
this my app.url.py:
from django.urls import path
from . import views
urlpatterns = [
path('/redirect/' , views.sendmail, name='sendmail'),
]
this my url.py:
urlpatterns = [
path('', include('register.urls')),
path('admin/', admin.site.urls),
]
this is my change_form.html that override admin templates:
{% extends "admin/change_form.html" %}
{% load i18n %}
{% block submit_buttons_bottom %}
<a href="{% url 'sendmail'%}"> <input type="button" value="Click" name="mybtn" /></a>
{% if messages %}
<ul class="messagelist">{% for message in messages %}<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>{% endfor %}</ul>
{% endif %}
{{ block.super }}
{% endblock %}
and this my app image:
my app
when I click on the button the email was sent.
look at this
but, I want when the email was sent, just show an alert that email sent successfully.
my problem is, I don’t want to redirect to another page. what should I do?