Answer the question
In order to leave comments, you need to log in
How to make a form in ContextProcessor?
Good afternoon. I'm not writing a big project on DJANGO, and a little difficulty arose, I need a form that would be on all pages of my site, implemented through the contextprocessor. Like this
# -*- coding: utf-8 -*-
from django.shortcuts import render, redirect
from django.http import HttpResponse, HttpResponseRedirect
from .models import *
from price.models import price
from django.views.generic import View
from .forms import callMeForm
#from django.http import HttpResponse
from sms_signup.smsc_api import *
from sms_signup.forms import activations
from sms_signup.models import SMS_PHONE
from sms_signup.views import *
from django.db.models.query_utils import DeferredAttribute
#Контекстный процессор для описания формы сайта
def phone_form(request):
if request.method == 'POST':
zvonok_form = callMeForm(request.POST)
if zvonok_form.is_valid():
phone_form = zvonok_form
phone_form_name=phone_form.cleaned_data['name']
phone_form_phone=phone_form.cleaned_data['phone']
print(phone_form_name)
smsc = SMSC()
...
r = smsc.send_sms('79994406745', "Заказ звонка с сайта: " + str(phone_form_name)+ " " +str(phone_form_phone), sender= "sms")
zvonok_form.save()
return HttpResponse("OK")
else:
zvonok=callMeForm()
else:
zvonok=callMeForm()
return {'zvonok':zvonok}
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