Answer the question
In order to leave comments, you need to log in
How to send an email in Django 1.10?
Modal form window
<form id="callback" class="get-info" action="{% url 'callback:callback' %}" method="POST">
{% csrf_token %}
<input type="hidden" name="_subject" value="karpaty-perezvonite-mne" />
<div class="form-group">
<input id="callback" name="phone" type="tel" class="form-control" placeholder="+ 380 ___-__-__">
</div>
<input type="text" class="form-control" placeholder="" name="lastpath" value="/" style="display: none"/>
<button type="submit" class="btn btn-default" value="Send">Отправить</button>
</form>
@requires_csrf_token
def callback(request):
phone = request.POST.get('phone', None)
text = u'Вас просят перезвонить по номеру: ' + phone
if request.method == 'post':
c = {}
send_mail('Заказ обратного звонка', text, '[email protected]',
['[email protected]'], fail_silently=False)
return render(request, 'index.html', c)
url(r'^callback/', include('callback.urls', namespace="callback")),
from django.conf.urls import url
urlpatterns = [
url(r'^callback/$', views.callback, name='callback'),
]
CSRF_COOKIE_SECURE = True
MIDDLEWARE = [
'django.middleware.csrf.CsrfViewMiddleware',
]
TEMPLATES = [{
'OPTIONS': {
'context_processors': [
'django.template.context_processors.csrf',
],
},
},
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question