Getting started with Django web framework : Part 1

by Tom Victor Posted on June 23, 2017, 8:50 a.m.

Introduction

As you all know python is one of the powerful modern programming languages, you can extend your Python skill to the server side backend development, REST API processing, Web App Development, Mobile App Backend using the Django Web framework. Django powers a lot of modern Apps we use every day some of them are

  • Instagram
  • Pinterest
  • Disqus
  • Washington Post
  • NASA

Source: https://www.shuup.com/en/blog/25-of-the-most-popular-python-and-django-websites/

Step 1(Initial set up): 

Navigate to your Desktop on terminal and create  a new folder called Django

Django

Navigate the new folder(using cd command), Now we will create a new virtual environment for our project, virtual environment helps us to isolate this project and its dependencies from the other apps on our computer.

virtual env

Here I am using python version 3 (You can also try Python 2.7). Type the following command for new virtual "myenv"

virtualenv myenv -p python3

Now a new folder called "myenv" will be created in the current directory. for activating the new virtual environment type the following command

source myenv/bin/activate

Now you can view the current python interpreter typing the following command

which python

Django

Step 2 (Install Django):

Install Django using the following command

pip install django

 

Django beginners

Now type freeze command to check whether the installation is successful

pip freeze


python

Step 3 (Start project):

Now start a new Django by typing the startproject command, here I am starting a project called "Django bin", you also give a different name

django-admin startproject djangobin

python website

Open the project in your favorite IDE, Here is the Sublime Text 3

python - django - tutorial

Step 4 (Migrations):

Now we have to create database tables for the Django default settings, for that, we will type the migration command. This command will create a new SQLite database file in the root directory. The default database table will contain the user model,  session and CSRF tokens and more, no need to care about those at this point.

 django migrations

Step 5(Run server):

Unlike other traditional stacks, the Django came with an inbuilt server for the easy development. So we don't need to configure a local Apache server and MySQL instance. You just need to type a simple command for runserver. ie

python manage.py runserver

 

django python

The above command will run a development server on your local comouter. the default port is 8000, you can also chane this to any port by providing it as arguments. Now open your favorite web browser of choice and go to 127.0.0.1:8000 . You will be able to see the django welome page.

django welcome, scratch tutorial

 

Download the source code from github.com/buildfromzero