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:

RIP Steve Jobs

October 6th, 2011

I say good-bye to a great visionary, one of my idols in the computer industry.

http://www.telegraph.co.uk/technology/steve-jobs/8810743/Steve-Jobs-tributes-to-the-Apple-co-founder.html

Rest in Peace Steve Jobs. Thank you for making the world a better place to live in.

Author: Cyril Pauya Categories: General Tags:

How to display contents of file in Ubuntu terminal

February 20th, 2011

I always forget how to do this so I’m putting it here for my own reminder.

When you are on Ubuntu’s terminal or shell, this is the command on how to display the contents of a file in Ubuntu:

$ cat file.txt

Pretty easy huh!

Author: Cyril Pauya Categories: how-to Tags: , ,

Screen your way on Ubuntu Linux

October 31st, 2010

We have plenty of experience deploying Django applications to remote servers, mostly on Webfaction. But the latest server we deployed to was a Debian Lenny VPS server. Since Ubuntu was of a Debian family, it’s been quite easy. The problem is if you have a reliable internet connection to the server half-way around the globe.

I’m on a mobile broadband internet connection since we moved to Davao City. That means I got an unreliable internet connection. So typing “tail -f /var/log/apache2/error.log” would take a few seconds to echo on your shell. Now imagine having to type that every time you make changes to your Apache configuration files?
Read more…

Halalan 2010 – First Automated National Elections in the Philippines

May 10th, 2010

I just finished voting in the Halalan 2010 – the First Automated National Elections in the Philippines.  It was an exciting experience for me as a Filipino, although as a programmer and a techie guy, I do have some apprehensions.
Read more…

Author: Cyril Pauya Categories: Politics Tags: , ,

Mercurial GUI Client on Ubuntu

April 15th, 2010

There are a lot of options for a Mercurial GUI client on Ubuntu but I preferred to use TortoiseHg so that I could use it with Nautilus – Ubuntu’s file manager.

TortoiseHg however is not in the Ubuntu Karmic Koala repositories.  Another challenge is that TortoiseHg 1.0.1 requires Mercurial 1.5 but Ubuntu Karmic only has Mercurial 1.3 on the repositories.  Of course I want the newer versions. :)

Here are the steps I did to install TortoiseHg, my preferred Mercurial GUI client on Ubuntu Karmic Koala 9.10:
Read more…

How to Install Agilo on Trac at Webfaction

December 30th, 2009

Here are the steps I did to successfully install Agilo for Scrum (open-source version) in my Trac site at Webfaction.com:
Read more…

Fix for JPEG upload problem in Django in virtualenv

December 2nd, 2009

I have been busy modifying Django‘s models for a project to include a field for uploading an image and was testing the model using Django’s Admin interface when I suddenly got this error:

Upload a valid image. The file you uploaded was either not an image or a corrupted image.

Read more…

Author: Cyril Pauya Categories: programming Tags: , , , , ,

Django in Production

October 20th, 2009

Here are some quick tips when moving your Django site into production.
Read more…

Author: Cyril Pauya Categories: Software, programming Tags: ,