Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.http import HttpResponse
- from django.template.loader import render_to_string, get_template
- from django.core.mail import EmailMessage
- from django.views.generic import TemplateView
- from app.models import Prueba
- def email_one(request):
- subject = "I am a text email"
- to = ['micorreo@gmail.com']
- from_email = 'micorreo@gmail.com'
- ctx = {
- 'user': 'admin',
- }
- message = render_to_string('email.txt', ctx)
- EmailMessage(subject, message, to=to, from_email=from_email).send()
- return HttpResponse('email_one')
- def email_two(request):
- subject = "I am an HTML email"
- to = ['micorreo@gmail.com']
- from_email = 'micorreo@gmail.com'
- ctx = {
- 'user': 'admin',
- }
- message = get_template('index.html').render(dict(ctx))
- msg = EmailMessage(subject, message, to=to, from_email=from_email)
- msg.content_subtype = 'html'
- msg.send()
- return HttpResponse('email_two')
- class PruebaListView(TemplateView):
- model = Prueba
- template_name = 'index.html'
- def get_context_data(self, **kwargs):
- context = super(PruebaListView, self).get_context_data(**kwargs)
- list_prueba = Prueba.objects.all()
- context['list_prueba'] = list_prueba
- return context
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement