# Topic covered
1.1 What is Django?
Django is a Python-based
web application framework
that is free and open source
.
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 makes development quick and easy
1.2 Companies that make use of Django framework?
- Instagram,
Bitbucket
, Mozilla Firefox Pinterest
, DiscusNASA
, 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
- DRY philosophy —
- 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
- It enables you to
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.
- Is
- manage.py
- A
command-line utility
that lets you interact with the Django project in various ways.
- A
- inner mysite/
- The inner mysite/ directory is the actual
Python package
for your project.
- The inner mysite/ directory is the actual
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
- Contains the
- 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
- The module is a simple Python file that contains
- 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
- The package is a simple directory having
- Library
- Library is 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.
- Library is a
- 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.
- Framework is a
1.9 Projects vs Apps in Django
- Apps
- A Django App is like
a component for our project
which provides us with particular functionality - We can have components like:
accounts
,customers
,blogs
etc.
- A Django App is like
- 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.
- A Django project is your
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`