Django Introduction

1.1 What is Django?

  • Django is a high-level web development framework
  • Based on Python
  • Free and open source
  • Enables Web development to develop quickly and with ease
  • Maintained by Django Software Foundation

1.2 Companies that make use of Django framework?

  • Instagram, Bitbucket, Mozilla Firefox
  • Pinterest, Discus
  • NASA, Onion, The Washington Post
  • Eventbrite, Mahalo

1.3 Advantage of Django

  • Easy to use
    • Uses python
    • Has large community of developers
  • Fast and Simple
    • DRY philosophy — Don’t Repeat Yourself
  • Excellent documentation
    • Has real-world applications
  • It’s secure from
    • clickjacking
    • cross-site scripting
    • SQL injection
  • Other
    • It enables you to separate business logic from the HTML
    • For website administration, it provides auto-generated web admin

1.4 Feature in Django framework

  • Admin Interface (CRUD)
  • Security Features
  • Object-relational mapping (ORM)
  • Templating
  • Session, user management, role-based permissions
  • Testing Framework
  • Form handling
  • Fantastic Documentation
  • SEO

1.5 Disadvantage

  • Django' modules are bulky.
  • It is completely based on Django ORM.
  • Components are deployed together.
  • You must know the full system to work with it.

1.6 Design philosophies

  • Loose coupling
  • Less code
  • Quick development
  • Don’t repeat yourself (DRY)

1.7 File Structure Info

mysite/
  manage.py
  mysite/
    __init__.py
    settings.py
    urls.py
    asgi.py
    wsgi.py
  • outer mysite/
    • Is root directory, just a container for your project.
    • Its name doesn’t matter to Django, you can rename it to anything you like.
  • manage.py
    • A command-line utility that lets you interact with the Django project in various ways.
  • inner mysite/
    • The inner mysite/ directory is the actual Python package for your project.
  • mysite/__init__.py
    • An empty file that tells Python that this directory should be considered a Python package.
  • mysite/settings.py
    • Settings/configuration for this Django project.
  • mysite/urls.py
    • Contains the URL’s for the current project
    • The URL declarations for this Django project
  • mysite/wsgi.py
    • Web Server Gateway Interface
    • Synchronous Python apps
    • An entry-point for WSGI-compatible web servers to serve your project.
  • mysite/asgi.py
    • Asynchronous Server Gateway Interface
    • Successor to WSGI
    • For both asynchronous and synchronous apps,
    • An entry-point for ASGI-compatible web servers to serve your project.

1.8 Script vs Modules vs Package vs Library vs Framework

  • Script
    • A script is generally a directly executable piece of code, run by itself.
    • Convenient execution from command line
  • Modules
    • The module is a simple Python file that contains various functions and global variables.
    • Convenient import with API
    • modules.py
    • from modules import mod
  • Package
    • The package is a simple directory having collections of modules
    • It also has __init__.py file by which the interpreter interprets it as a Package
    • pack/mod1.py, pack/mod2.py
    • from pack.mod1 import mod
  • Library
    • Libraryis a collection of packages
    • Numpy, Pandas, Matplotlib etc..
    • When you use a library, you are in charge of the flow of the application.
      • You are choosing when and where to call the library.
  • Framework
    • Framework is a collection of libraries
    • Django, Flask
    • When you use a framework, the framework is in charge of the flow.
      • It provides some places for you to plug in your code, but it calls the code you plugged in as needed.

1.9 Projects vs Apps in Django

  • Apps
    • A Django App is like component for our project which provide with us particular functionality
    • We can have components like: accounts, customers, blogs
  • Project
    • A Django project is your entire application
    • It’s a collection of one or many apps
    • A project can contain multiple apps
    • And an app can be in multiple projects.

1.10 Django vs Flask

1. Project Type:
    * Django 	-- used for `large projects`
    * Flask 	-- used for `smaller projects`
2. Feature (`Admin, Templates, ORM`)
    * Django 	-- Built in
    * Flask  	-- Requires installation
3. Ease of Learning
    * Django 	-- `More learning` and Practice requires
    * Flask 	-- Easy to learn
4. Type of Framework
    * Django    -- Batteries included, `Heavy weight`
    * Flask	-- `Simple` and `lightweight`

Reference