Thursday, November 30, 2017

Django Learn Series | Creating a Django App


  1. cd Desktop/DjangoPractice/firstdjango
  2. python manage.py startapp firstapp
  3. Files inside firstapp folder are below
    1. models.py -- DB interaction
    2. admin.py -- admin interface
    3. views.py -- App's logic and URL request / response
    4. tests.py -- Automated tests 
    5. migrations folder -- auto generated. Migration files about DB tables changes for the app

Django Learn Series | Creating a Django project



  1. source djangoTestEnv/bin/activate
  2. Create a folder like DjangoPractice on Desktop
  3. cd Desktop/DjangoPractice
  4. django-admin startproject firstdjango
    • Auto creates  a folder named firstdjango and required files in it
    • Subfolder named firstdjango inside firstdjango will have 
      • init.py
      • settings.py
        • Configures Django
      • urls.py
        • Routes requests based on URL
      • wsgi.py
        • provides a hook for webservers
        • WSGI is the Web Server Gateway Interface. It is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request.
        • WSGI is a Python standard described in detail in PEP 3333.
    • main folder firstdjango will have manage.py
    • manage.py runs commands related to firstdjango
  5. cd firstdjango
  6. python manage.py
    • To check list of available command
  7. python manage.py runserver
    • To start the webserver

Django Learn Series | Installation


On Ubuntu Machine, use below steps.

  1. sudo -H pip install virtualenv
    • Using pip and installing virtualenv (recommended) instead of global installation
  2. virtualenv -p python djangoTestEnv
    • djangoTestEnv is sample name of virtual environment
  3. source djangoTestEnv/bin/activate
    • Activating djangoTestEnv
  4. pip install django
    • Installing django in djangoTestEnv
  5. pip freeze
    • This is to check installed packages in that  djangoTestEnv
  6. django-admin --version
    • This is to check the version of django installed in djangoTestEnv