Getting Started with django with ubuntu

Tag line for django says “The web framework for perfectionists with deadlines.” and most would agree. django is rediculously fast to implement, its fully loaded with lots of utilitis, its secure and at the same time its highly scalable. some of the most popular sites like instagram, pinterest are built with django.

Let us get our hands dirty by getting started with django instead of talking about django features.

Which django version should I use ?

Here are the details about djnago release. you can choose latest version, however, I will stick with LTS version

Currently I am using Django 2.2 for most of my projects.

Which Python version should I use ?

This is the most common question and following table with clarify your query

Django version Python versions
  1.11 2.7, 3.4, 3.5, 3.6
  2.0 3.4, 3.5, 3.6, 3.7
  2.1,2.2 3.5, 3.6, 3.7

In this tutorial we are going to use python version 3.6 (3.6.4 to be very specifuc) and django version 1.11.

Install django version 1.11

$ sudo python3.6 -m pip install django==1.11
Collecting django==1.11
Downloading (6.9MB)
100% |████████████████████████████████| 6.9MB 339kB/s 
Requirement already satisfied: pytz in /usr/local/lib/python3.6/site-packages (from django==1.11) (2017.3)
Installing collected packages: django
Successfully installed django-1.11

You can check the version as below

$ python3.6 -m django --version

Creating django project

$ django-admin startproject mysite

Now CD into directory “mysite” and run following command

$python3.6 runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python migrate' to apply them.

July 18, 2018 - 17:43:11
Django version 1.11, using settings 'mysite.settings'
Starting development server at
Quit the server with CONTROL-C.
[18/Jul/2018 17:43:31] "GET / HTTP/1.1" 200 1716
Not Found: /favicon.ico

Now you can access django website at location

here is the output

Creating application

Now that your environment – a “project” – is set up, you’re set to start doing work.

$ python3.6 startapp polls

after creating polls app, please add following code to polls/

from django.http import HttpResponse

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

Now create a file and add following code

from django.conf.urls import url

from . import views

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

Now add following code in

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

urlpatterns = [
    url(r'^polls/', include('polls.urls')),

Here is the output

Hope this is helpful…

MySQL Quick Reference

Here is the list of commands for MySQL that will be evry handy while using MySQL. Over the period of time, you will remember these commands but to get started, you can use this as a cheat sheet for MySQL commands.

Connecting to MySQL

  • Check status of MySQL
$ systemctl status mysql
  • Start and Stop MySQL Server using
$ sudo systemctl start mysql
$ sudo systemctl stop mysql
  • Start MySQL without admin privileges
sudo mysqld_safe --skip-grant-tables --skip-networking &  
  • After installation defact userid and password can be viewed by using following command
sudo cat /etc/mysql/debian.cnf

host = localhost
user = debian-sys-maint
password = XXX
socket = /var/run/mysqld/mysqld.sock
host = localhost
user = debian-sys-maint
password = XXX
socket = /var/run/mysqld/mysqld.sock
  • Login to MySQL Database from command line. Once authentication is completed successfully, mysql> prompt will appear.


$ mysql --host=localhost --user=USERNAME --password PASSWORD

If you want to connect to any remote MySQL server, replace ‘localhost’ with remote db address name and add port parameter.

$ mysql --port=13306 --user=USERNAME --password PASSWORD

Commands to be used in mysql> prompt:

Use following command to get list of databases

mysql> show databases;

Use following command to create database

mysql> create database <newDatabaseName>;

Create new user

mysql>CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

grant access to newly created user

mysql> grant create, delete, insert, select, update, alter,references ON <databaseName>.* TO 'usernmae'@'localhost';

Use following command to delete or drop  database

mysql> drop database DatabaseName;

Use following command to get list of users

mysql> SELECT User FROM mysql.user;


To check the access level of the user

mysql>SHOW GRANTS FOR 'root'@'localhost';

To use specific database name use following command

mysql>use DBNAME

To export database.

Please note that password is not put after “-p”, there will be prompt for password where you need to provide the password.

$mysqldump -u [username] -p [databaseName] > [databaseName].sql

To import database

$mysql -u [username] -p newdatabase < [databaseName].sql