Send Emails Asynchronously from Django

Posted on Sun 24 January 2016 in Django • Tagged with django, python, celery, emailsLeave a comment

In this article you will learn:

  1. How to send emails from Django.
  2. How to use Celery and Django-Celery-Email to send email asynchronously.

Last week I had the chance to get my hand dirty with Celery, I used it to send emails from Django project asynchronously using Django app call djnago-celery-email. What am I mean by sending emails asynchronously? I mean that user doesn’t wait for SMTP/mail server to send email message and give feedback to the web server, instead Django will call the send email procedure, pass it to Celery to do it away from Django application, so that user won’t wait, for example you want to send email to customer once he save customer information, you don’t want to keep user wait for application to save the customer data and send email, by sending email asynchronously user will only wait for saving confirmation and sending email celery will take care of it in the background.

Alt Text

Now let’s see how we can do that.

Step 1: Install and Setup Celery

  • In terminal, active your virtualenv and type $ pip install django-celery
  • Now celery and its Django app djcelery are installed into your virtualenv.
  • Next step is …
Continue reading

Extend Django User Model and Generic Class Based View "GCBV"

Posted on Fri 18 December 2015 in Django • Tagged with Django, PythonLeave a comment

1450356512_full.png When I started to learn Django, I used to use the function based view aka FBV and in my current project I decided to learn class based view CBV, I watched one DjangoCon videos by Andrew Pinkham to make this easier on me, and if you tried or planning to learn CBV, you will be confused about the class based views and the generic class based views inside Django, it’s some many of them, please watch the video to get your head around it. OK, now I’ve done my homework and it’s time to use CBV, believe me it’s easy and you will find the number of code lines inside our views will be decreased specially if you use GCBV. User Model and GCBV

What is the relation between GCBV and User Model?

Great question, while I’m working with one of my models fro example her the Teacher model, and teacher will has a user credentials in order to user the app. The easiest and the straightforward way is to make one-to-one relation with django.contrib.auth.models.User please read the quote from Django documentation:

There are two ways to extend the default User …

Continue reading

Free Django hosting

Posted on Sun 19 April 2015 in Django • Tagged with django, pythonLeave a comment

If you developed Django application and want to deploy/publish it to the web you can check this list of Django friendly (, but if you want a free hosting you can use Python Anywhere free hosting, I’m using it for my Django app and I’m very comfortable with but before using the free hosting please consider the following:

  1. They provide only MySQL for free hosting, so if you developed your app using PostgreSQL or SQLite, please download the correct driver.
  2. Application URL must be sub-domain of, example
  3. I’ll host one application only.
  4. No full access to a machine, you’ll deploy your application using console, use the console to install your virtual environment and packages, and edit some code using their in-browser code editor.

How to deploy?

  1. First go to this link and register your free account, then 
  2. Go to your dashboard, and select Consoles tab.
  3. Click on Python 2.7 (I personally still using python 2.7 but if you want select python 3.3) to open a new console.
  4. New console will open in your browser.
  5. Start by creating your virtualenv and install the required packages …
Continue reading

My First Django App

Posted on Mon 16 March 2015 in Django • Tagged with django, python, sideprojectLeave a comment

I'm starting to use Django and Python to develop web applications, I really love Django and during my learning process I thought I can build something while learning, and I had one idea keep it on hold as side project so I decided it's time to build it.

The Idea

Me and my wife have our financial system which is dividing the monthly budget into a weekly budget, most of us make budget on monthly basis because we get paid on monthly basis, but imagine your budget will be on weekly basis, it’s like every week is new budget and new start, and in order to keep track of the weekly budget you need to know how much you need to spend in a week. To be honest in the first we made a lot of mistakes but at the end we found out how much we need to spend weekly, and this need analysis with trial and error for at least one month then you will master your weekly budgeting.

Now the idea is build a system that can keep track of your payments or expenses against your estimated budget for a week. The application name is Ma3ana …

Continue reading

Virtual Environment

Posted on Sun 01 March 2015 in Python • Tagged with django, pip, python, virtualenvLeave a comment

While leaning web developing using Django and Python, I found out VirtualEnv or Virtual Environment is widely used, in first I didn't get it because I came from Microsoft .NET Framework development platform, so I thought of writing a post about it to make simple.

What is Virtual Environment?

VirtualEnv or Virtual Environment is a way to create isolated development environment each one has it's own packages and specific package version, for example VirEnv1 has Django 1.6 and VirEnv2 has Django 1.7, this isolation will keep your project packages dependency clear, isolated, and as I'll show you below that you can replicate the environment with one command and file, so if you work in team it's easy to share the same environment among the team.

virtualenv 1 virtualenv 2

How to install VirtualEnv?

VirtualEnv is a python package so to install is you need to install pip first.

  1. Open terminal and type the following command

    sudo apt-get install python-pip

  2. After finish installing pip type the following command to install virtual environment

    sudo pip install virtualenv

  3. After finish installing virtualenv, type the following command to create folder to store your virtual environments

    mkdir .virtualenvs

How to create virtualenv?

After install virtualenv you are …

Continue reading