Archive

Author Archive

django send email

September 3rd, 2013

Mail is sent using the SMTP host and port specified in the EMAIL_HOST and EMAIL_PORT settings. The EMAIL_HOST_USER and EMAIL_HOST_PASSWORD settings, if set, are used to authenticate to the SMTP server, and the EMAIL_USE_TLS and EMAIL_USE_SSL settings control whether a secure connection is used.

add this code to setting.py as your email account

ALLOWED_HOSTS = []
EMAIL_USE_TLS = True
EMAIL_HOST = ‘smtp.example.com’
EMAIL_HOST_USER = ‘test@example.com’
EMAIL_HOST_PASSWORD = r’example’
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = ‘My Company ‘
SERVER_EMAIL = ‘webmas…@example.com’

views.py

from django.template.loader import render_to_string

def send_email(request):
    message = render_to_string(email.html)

    send_mail('Subject here', message, 'from@example.com',
    ['to@example.com'], fail_silently=False)

reference: https://docs.djangoproject.com/en/dev/topics/email/

Author: Richard Amodia Categories: programming Tags:

django create Function to delete all session

August 23rd, 2013

definition: session stores data on the server side and abstracts the sending and receiving of cookies, Delete the current session data from the session and regenerate the session key value that is sent back to the user in the cookie.

purpose: This is used if you want to ensure that the previous session data can’t be accessed again from the user’s browser.

views.py

def delete_session(request):
    # session to be deleted
    session = request.session
    del session['session1']
    del session['session2']
    del session['session3']
    del session['session4']
    del session['session5']

*use the “”delete_session(request)”" Function name to delete session.

*I have an example below on how to use the created delete_session function.

def final_session(request):
    # function name
    delete_session(request)

    template = 'final_session.html'
    context = {}
    return render(request, template, context)
Author: Richard Amodia Categories: programming Tags: