#Views
from django.conf import settings
from django.shortcuts import render
from django.core.mail import send_mail
from django.core import mail
from django.template.loader import render_to_string
from django.utils.html import strip_tags
import mysql.connector
from . import models
# Create your views here.
mydb=mysql.connector.connect(host="localhost",user="root",password="",db='ayush')
print(mydb)
mycursor=mydb.cursor()
if(mydb):
print("connection sucessful")
else:
print("connection unsucessful")
def index(request):
name = request.POST.get('name')
models.Data.objects.create(name=name)
email=request.POST.get('email')
models.Data.objects.create(email=email)
phone=request.POST.get('phone')
models.Data.objects.create(phone=phone)
subject = 'Call For Help'
html_message = render_to_string('index.html', {'context': 'values'})
plain_message = strip_tags(html_message)
from_email = 'From <bloodnepal22@gmail.com>'
to=[email]
mail.send_mail(subject, plain_message, from_email,
return render(request, 'index.html')
#models
from django.db import models
# Create your models here.
class Data(models.Model):
name=models.CharField(max_length=500)
email=models.CharField(max_length=500)
phone=models.CharField(max_length=500)
def __str__(self):
return '{}'.format(self.name)
↧
How can i send e-mail to multiple people stored in MY-SQL database using Django? I have created models and views but it is not working [closed]
↧