What is Django?
● Django is Python’s most popular web framework.
● Lawrence Journal-World is the popular daily newspaper publishing
company who started developing web framework for publishing news over
website. That framework is known as the Django web framework.
● At present the development is going under the Django Software
● Initially it was started before 10 years!
Benefits of Django
● Open source
● Large community base
● Fast Web application development
Who is using Django?
● Open Stack
MVC vs MVT
● Django is MVC but usually people call it Model View Template
● The Model part is used for all the Data Base operations and managing
record as object
● View part is used for managing, filtering, creating, deleting records of
● Template part is used for combining model object with the HTML
Create virtual environment
● You can use `venv` builtin module of Python.
○ `python3 -m venv my_virtualenv`
● Always dump your installation package to `requirements.txt` file.
○ $>pip freeze > requirements.txt
● The requirements.txt is a not a fix file name. It is just a convention.
Create a website
● Create website first
○ django-admin startproject mysite
● Here, `mysite` is name of website.
● Mysite directory
● ├── manage.py
● ├── mysite
Project vs App
● App is pluggable project
● Django follows DRY principle
● Project is a website in which there can be more than one collection of app.
Blog Post model structure
● Create date
Adding fields to model
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(auto_now_add=True)
published = models.BooleanField(default=False)
author = models.ForeignKey(User, blank=True, null=True)
A walk on Django migrations
● Migrations are app specific thing
● Always commit them
● Why migrations?
● Django will warn when you will make incompatible migrations
● ├── migrations
● │ │ ├── 0001_initial.py
Create urls Blog
● List post(http://localhost:8000/post/)
○ url(r'^$', views.list_post),
● Single post (http://localhost:8000/post/id)
○ url(r'^(?P<post_id>[0-9]+)/$', views.single_post, name='single_post')
How to learn Django?
● Read tutorials section divided into 6 parts of Django
● Contribute to any live project
○ Make website for your community
○ Try to SaaSify (SaaS) any existing tool
○ Help Pythonexpress.in (https://github.com/pythonindia/wye)
○ Do volunteering