Install Python

Django is a Python web framework, thus requiring Python to be installed on your machine.

To install Python on your machine go to https://python.org/download/, and download a Windows MSI installer for Python. Once downloaded, run the MSI installer and follow the on-screen instructions. As of writing this article, there were two available versions of python: 2.7.11 and 3.5.1.

I chose Python 2.5.11 since there are still several software that doesn't support Python 3.x

After the installation is completed you need to add python path to your environment variable. So if you your installation path is c:\python27 then your PATH variable should be set like this:

C:\Python27\;C:\Python27\Scripts;

Verify installation by executing python --version in a command line.

Install PIP

PIP is a package manager for python which will be used to install Django. To install, execute easy_install pip from a command line. This will install pip on your system. If that doesn't work for you, go to https://pip.pypa.io/en/latest/installing/ and download get-pip.py.

Now run python get-pip.py to install pip. You may need to restart your system or command prompt to  confirm the installation. If you get an error like: 

'pip' is not recognized as an internal or external command

you need to make sure you have set the environment path correctly. Verify installation by executing pip --version in a command line.

Install Django

 To install django, execute pip install django from a command line. To verify installation, execute django-admin --version.

 

Creating a new Project in Django

To create a new project, browse to your project directory and execute, django-admin startproject myproject

 This will create myproject directory in your current directory.  Browse to this directory and run python manage.py runserver.

If everything works well, you should see a welcome page when you visit http://127.0.0.1:8000/ in your browser.

 Create a new app

An app is created to do something specific like logging, creating a voting system etc. A project can have multiple apps. To create a new app, type:

python manage.py startapp myapp

 This will create a new directory myapp inside the parent directory myproject

Setup Views

To write your first view, open myapp/views.py and add the following code to it:

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the myapp index.")

Setup Routing

To setup routes, create a new file urls.py inside myapp directory and paste the following into it:

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]

To make this work, you need to import this url file into the project urls.py file. Open the urls.py in the myproject directory and paste the following into it:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^myapp/', include('myapp.urls')),
    url(r'^admin/', admin.site.urls),
]

To see it in action, re-run the server and browse to  http://localhost:8000/myapp. You should see the text, "Hello, world. You're at the myapp index."

That sure will make you happy. Now let's move forward to the next step.