D.J.A.N.G.O Kalim Ullah
Introduction Django is a high-level Python web framework that enables rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. It is free and open source, has a thriving and active community, great documentation, and many options for free and paid-for support.
Installation  Installation guide https://github.com/mangrio123/Python-Django-Setup- Guide
PIP  Django requires pip to start installation.  Pip is a package manager system which is used to install and manage packages written in python.  For Python 3.4 and higher versions pip3 is used to manage packages.
Virtual Environment  The virtual environment is an environment which is used by Django to execute an application.  It is recommended to create and execute a Django application in a separate environment.  Python provides a tool virtualenv to create an isolated Python environment
Admin Interface  Django provides a built-in admin module which can be used to perform CRUD operations on the models.  It reads metadata from the model to provide a quick interface where the user can manage the content of the application.  This is a built-in module and designed to perform admin related tasks to the user.  Let's see how to activate and use Django's admin module (interface).
Django App  Django application consists of project and app, it also generates an automatic base directory for the app, so we can focus on writing code (business logic) rather than creating app directories.  The difference between a project and app is, a project is a collection of configuration files and apps whereas the app is a web application which is written to perform business logic.
Django MVT  The MVT (Model View Template) is a software design pattern. It is a collection of three important components Model View and Template.  M - The Model helps to handle database. It is a data access layer which handles the data.  V- The View is used to execute the business logic and interact with a model to carry data and renders a template.  T- The Template is a presentation layer which handles User Interface part completely.  Although Django follows MVC pattern but maintains its own conventions. So, control is handled by the framework itself.
URLs/Routes  Since Django is a web application framework, it gets user requests by URL locater and responds back.  To handle URL, django.urls module is used by the framework.
Middleware  In Django, middleware is a lightweight plugin that processes during request and response execution.  Middleware is used to perform a function in the application. The functions can be a security, session, csrf protection, authentication etc.  Django provides various built-in middleware and also allows us to write our own middleware.  See, settings.py file of Django project that contains various middleware, that is used to provides functionalities to the application.
Static Files Handling  Apart from business logic and data handling, we also need to handle and manage static resources like CSS, JavaScript, images etc.  Django deals with it very efficiently and provides a convenient manner to use resources.  Include the django.contrib.staticfiles in INSTALLED_APPS.  Define STATIC_URL in settings.py file as given below.  Load static files in the templates by using the below expression.
Database Migrations  Migration is a way of applying changes that we have made to a model, into the database schema.  Django creates a migration file inside the migration folder for each model to create the table schema, and each table is mapped to the model of which migration is created.  Django provides the various commands that are used to perform migration related tasks. After creating a model, we can use these commands.  makemigrations : It is used to create a migration file that contains code for the tabled schema of a model.  migrate : It creates table according to the schema defined in the migration file.  sqlmigrate : It is used to show a raw SQL query of the applied migration.  showmigrations : It lists out all the migrations and their status.
Model Form  It is a class which is used to create an HTML form by using the Model.  It is an efficient way to create a form without writing HTML code.  Django automatically does it for us to reduce the application development time.  For example, suppose we have a model containing various fields, we don't need to repeat the fields in the form file.  For this reason, Django provides a helper class which allows us to create a Form class from a Django model.
Django Forms  Django provides a Form class which is used to create HTML forms. It describes a form and how it works and appears.  It is similar to the ModelForm class that creates a form by using the Model, but it does not require the Model.  Each field of the form class map to the HTML form <input> element and each one is a class itself, it manages form data and performs validation while submitting the form.

Basic Python Django

  • 1.
  • 2.
    Introduction Django is ahigh-level Python web framework that enables rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. It is free and open source, has a thriving and active community, great documentation, and many options for free and paid-for support.
  • 3.
    Installation  Installation guidehttps://github.com/mangrio123/Python-Django-Setup- Guide
  • 4.
    PIP  Django requirespip to start installation.  Pip is a package manager system which is used to install and manage packages written in python.  For Python 3.4 and higher versions pip3 is used to manage packages.
  • 5.
    Virtual Environment  Thevirtual environment is an environment which is used by Django to execute an application.  It is recommended to create and execute a Django application in a separate environment.  Python provides a tool virtualenv to create an isolated Python environment
  • 6.
    Admin Interface  Djangoprovides a built-in admin module which can be used to perform CRUD operations on the models.  It reads metadata from the model to provide a quick interface where the user can manage the content of the application.  This is a built-in module and designed to perform admin related tasks to the user.  Let's see how to activate and use Django's admin module (interface).
  • 7.
    Django App  Djangoapplication consists of project and app, it also generates an automatic base directory for the app, so we can focus on writing code (business logic) rather than creating app directories.  The difference between a project and app is, a project is a collection of configuration files and apps whereas the app is a web application which is written to perform business logic.
  • 8.
    Django MVT  TheMVT (Model View Template) is a software design pattern. It is a collection of three important components Model View and Template.  M - The Model helps to handle database. It is a data access layer which handles the data.  V- The View is used to execute the business logic and interact with a model to carry data and renders a template.  T- The Template is a presentation layer which handles User Interface part completely.  Although Django follows MVC pattern but maintains its own conventions. So, control is handled by the framework itself.
  • 9.
    URLs/Routes  Since Djangois a web application framework, it gets user requests by URL locater and responds back.  To handle URL, django.urls module is used by the framework.
  • 10.
    Middleware  In Django,middleware is a lightweight plugin that processes during request and response execution.  Middleware is used to perform a function in the application. The functions can be a security, session, csrf protection, authentication etc.  Django provides various built-in middleware and also allows us to write our own middleware.  See, settings.py file of Django project that contains various middleware, that is used to provides functionalities to the application.
  • 11.
    Static Files Handling Apart from business logic and data handling, we also need to handle and manage static resources like CSS, JavaScript, images etc.  Django deals with it very efficiently and provides a convenient manner to use resources.  Include the django.contrib.staticfiles in INSTALLED_APPS.  Define STATIC_URL in settings.py file as given below.  Load static files in the templates by using the below expression.
  • 12.
    Database Migrations  Migrationis a way of applying changes that we have made to a model, into the database schema.  Django creates a migration file inside the migration folder for each model to create the table schema, and each table is mapped to the model of which migration is created.  Django provides the various commands that are used to perform migration related tasks. After creating a model, we can use these commands.  makemigrations : It is used to create a migration file that contains code for the tabled schema of a model.  migrate : It creates table according to the schema defined in the migration file.  sqlmigrate : It is used to show a raw SQL query of the applied migration.  showmigrations : It lists out all the migrations and their status.
  • 13.
    Model Form  Itis a class which is used to create an HTML form by using the Model.  It is an efficient way to create a form without writing HTML code.  Django automatically does it for us to reduce the application development time.  For example, suppose we have a model containing various fields, we don't need to repeat the fields in the form file.  For this reason, Django provides a helper class which allows us to create a Form class from a Django model.
  • 14.
    Django Forms  Djangoprovides a Form class which is used to create HTML forms. It describes a form and how it works and appears.  It is similar to the ModelForm class that creates a form by using the Model, but it does not require the Model.  Each field of the form class map to the HTML form <input> element and each one is a class itself, it manages form data and performs validation while submitting the form.