Advertisement
Guest User

Untitled

a guest
Jan 9th, 2018
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. from django.http import HttpResponse
  2. from django.template.loader import render_to_string, get_template
  3. from django.core.mail import EmailMessage
  4. from django.views.generic import TemplateView
  5. from app.models import Prueba
  6.  
  7. def email_one(request):
  8.     subject = "I am a text email"
  9.     to = ['giovannicadiz@gmail.com']
  10.     from_email = 'giovannicadiz@gmail.com'
  11.  
  12.     ctx = {
  13.         'user': 'admin',
  14.  
  15.     }
  16.  
  17.     message = render_to_string('email.txt', ctx)
  18.  
  19.     EmailMessage(subject, message, to=to, from_email=from_email).send()
  20.  
  21.     return HttpResponse('email_one')
  22.  
  23. def email_two(request):
  24.     subject = "I am an HTML email"
  25.     to = ['giovannicadiz@gmail.com']
  26.     from_email = 'giovannicadiz@gmail.com'
  27.  
  28.     ctx = {
  29.         'user': 'admin',
  30.  
  31.     }
  32.  
  33.     message = get_template('index.html').render(dict(ctx))
  34.     msg = EmailMessage(subject, message, to=to, from_email=from_email)
  35.     msg.content_subtype = 'html'
  36.     msg.send()
  37.  
  38.     return HttpResponse('email_two')
  39.  
  40.  
  41. class PruebaListView(TemplateView):
  42.     model = Prueba
  43.     template_name = 'index.html'
  44.  
  45.     def get_context_data(self, **kwargs):
  46.         context = super(PruebaListView, self).get_context_data(**kwargs)
  47.         list_prueba = Prueba.objects.all()
  48.         context['list_prueba'] = list_prueba
  49.         return context
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement