Python Core



Admission Enquiry Form


Django Framework

Django is an open source framework used to develop website and works on the web server.

What is a framework?

A framework is a particular set of rules, ideas which you use in order to deal with problems or to decide what to do.

Coming to Django:

  1. It is basically a high level python web application framework that enables the rapid development of web applications.
  2. It is an open source python framework.
  3. It follows the MVT (Model view template) architectural pattern.

Advantages of Django:

  1. It is fast and simple.
  2. It is secure.
  3. It suits any web app.
  4. It is well established.
  5. MVT support and Object-Oriented approach.
  6. Built- in authentication and authorization
  7. Packaging system.

Example of Django web applications:

  1. Youtube
  2. Instagarm
  3. Spotify
  4. Dropbox



The MVT (Model view template) architectural approach:

  1. The MVT is a software design pattern.
  2. Model- It is going to act as the interface of your data.
  3. View- The view is the user interface – what you see in your browser when you render a website.
  4. Template – A template consists of static parts of the desired HTML outputs as some special syntax describing how dynamic content will be inserted.

MVT Flowchart:



Installation of Django::

  1. Install python from python.org and run the installation.
  2. Click on Add python to path in the installation wizard and also click on customize installation and select all the options and click on install.
  3. Now to check if the python has been installed, open cmd and type command python. This will show the installed python version.
  4. Now to check packages installed in python, run the command pip freeze.
  5. To install django, run the command pip install django.
  6. Now, to check if django has been installed, run command pip freeze. It will show the packages installed.



Creating a new Project in django:

  1. Open cmd and run the command django-admin. This will show all the commands in django-admin.
  2. Now to create a new project in django, we will first change the directory to the new folder in which you want to create the new project.
  3. Run the command, django-admin startproject projectname. This will create a new project folder.



Running a development server:

  1. Open cmd and change the current directory to the django project folder using cd command.
  2. Now, run the development server (project) using the command python manage.py runserver. This will start the server on port 8000.
  3. You can check the server by visiting the url provided by the cmd on running the command i.e localhost:8000.
  4. To stop the server we can use Ctrl+C.
If we want to run the project on any other port, we can use the same command but with the port number as parameter. Python manage.py runserver portnumber



Project Building through VSCode::

Installing VSCode:

  1. Download Visual studio code setup from their official website.
  2. Now run the setup file and install.
  3. Open VSCode and install extensions for python, django, django templates, html css support.
  4. Now click on File > open folder to open your django project folder.
  5. Now click on Terminal > new terminal.
  6. We can run our commands in this terminal instead of cmd.
  7. Change the directory to your project directory using cd command.
  8. Now run the command, python manage.py runserver to start the development server.



Folder structure of django:

  1. Open file explorer and open your project folder.
  2. In the first project folder, create new folders and name them templates, static, media.
  3. Templates folder will store all the HTML files from your project.
  4. Static folder will store all the static files i.e. JavaScript, CSS, JQuery etc.
  5. Media folder will store all the dynamic img from your project.



Migrating Default Migrations to sqlite3 database:

  1. Open terminal on your VSCode and change the directory to your project folder.
  2. Now to migrate the tables, run the command python manage.py migrate.