request should be ajax and method should be POST.
if request.is_ajax and request.method == "POST":
# get the form data
form = ContactForm(request.POST)
# save the data and after fetch the object in instance
if form.is_valid():
name = form.cleaned_data.get('name')
phone = form.cleaned_data.get('phone')
email = form.cleaned_data.get('email')
body = form.cleaned_data.get('body')
instance = form.save()
# serialize in new friend object in json
# send to client side.
ser_instance = serializers.serialize('json', [instance, ], indent=4)
telegram_bot_send_text(f"У вас новая заявка с контатной формы!\n"
f"Имя: {name}\n"
f"Телефон: {phone}\n"
f"Email: {email}\n"
f"Запрос: {body}\n")
# send to client side.
return JsonResponse({"instance": ser_instance}, status=200)
else:
# some form errors occured.
return JsonResponse({"error": form.errors}, status=400)
# some error occured
return JsonResponse({"error": ""}, status=400)
меня сильно смущает telegram_bot_send_text
Обсуждают сегодня