Django Template and URL Configuration

There are 4 steps to setting up template and URL configuration

Step 1: Open the file in your project folder and update the template section highlighted in the screenshot

Screen Shot 2015-11-07 at 8.23.45 AM

Step 2: Go to your application root, create a folder named templates and then create a file called home.html

<your project folder>

——– <your app folder>

——–    ——— /templates/home.html

Step 3: Open the file under your application and add the following

Screen Shot 2015-11-07 at 8.33.24 AM

Step 4: Open the file under your project folder, import the view from your project and add the url pattern to route any root or request to the home.html

Screen Shot 2015-11-07 at 8.37.39 AM

That’s all there is to it.  You should see the following when you browse to

Screen Shot 2015-11-07 at 8.39.33 AM

Initial database setup with Django

For this example, I am using Sqlite.  Once your Django server is setup, execute the following within your project forlder.

$ python migrate

You should see similar output in your screen

Screen Shot 2015-11-01 at 9.44.05 AM

At this point, the database is initialized.  Now, you have to create an admin user to administer your database.  Execute the following within your project folder

$ python createsuperuser

You screen output should look like the following

Screen Shot 2015-11-01 at 9.48.45 AM


Install Django on Mac with PIP and VirtualEnv

PIP is Python’s package installer.  VirtualEnv is a package within Python.  You don’t have to install or use virtual environment (virtualenv). It makes your life easy when you move from one computer to another. You can simply copy your virtual folder to where you want to work and all of your settings will be ported.

To install PIP, execute the following
$ sudo easy_install pip

To install virtualenv – Python’s package, execute the following
$ sudo pip install virtualenv

To create a virtual environment, go to the folder where you want to create your environment and execute the following
$ virtualenv myXYZprojectWork

Go to myXYZprojectWork folder. You will see subfolders (/bin, /include, and /lib) created under myXYZprojectWork.

To get in to the virtual environment, execute the following
$ source bin/activate

To check what packages are installed in the virtual environment, execute the following
$ pip freeze

To install the latest version of django, exute the following
$ pip install django

To upgrade django to the latest version, execute the following
$ pip install django –upgrade

Within your virtual environment, you can create your project executing the following
$ startproject myProject

The process will create a project and a subfolder called myProject.

To start the server with your project within the virtual environment, go inside myProject folder and execute the following
$ python runserver

To check your django server running, browse to

Sending SMS messages with Python

Sending text messages with Python is super simple.  First, sign up for an account (FREE or Paid Subscription) with Twilio.  This library works without any complexity and the API is easy to follow.  You can use the following example.  Don’t forget use your own information (SID, Auth Token, from and to numbers) before executing the code.

Screen Shot 2015-09-25 at 6.26.43 PM

Install the Twilio Package on Mac

I am using Twilio to do SMS/Text messaging from Python.  There are 2 ways to install the package, either use easy_install or pip.  Make sure you are using Python 2.7.  Here is how I installed the package on Mac

  • Macintosh will already have Python added in their system PATH.
  • The only step you need to take is to load up the Terminal application and type in easy_install twilio.
  • If you want to install Twilio with pip, you may need to first install pip on your system because newer Mac may not come with pip installed.
    • To do that you should first install pip with easy_install pip
    • You can then use pip to install Twilio with pip install twilio

To check whether Twilio was properly installed, enter the python command to enter the Python interpreter in the Terminal application and type in these two commands:

import twilio

It should print the version like 4.5.0

Force empty the trash in Mac

Sometimes, emptying the Trash in Mac can be very challenging.  For various reasons the trash bin will not empty or will take a long time to tell us why it couldn’t be done with not so good explanation. Here is an alternate way you can empty the trash.

1. Open the Terminal (Command + Space and then type Terminal and hit enter)

2. In the Terminal window after the $, type in the following and hit enter (be super careful – no extra space after the ~). Type in your super secret password

sudo rm -rf ~/.Trash

Voila… everything gone from the trash!