The talk was presented at PyDelhi conf 2017 (https://conference.pydelhi.org/). Core motive is to teach Django framework to user who wanted to learn it or want to start development in Django.
3. 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
Foundation
● Initially it was started before 10 years!
4. Benefits of Django
● Open source
● Large community base
● MVC
● Secure
● Fast Web application development
● Scalable
5. Who is using Django?
● Pinterest
● Instagram
● Mozilla
● Bitbucket
● NASA
● Open Stack
6. 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
Model
● Template part is used for combining model object with the HTML
templates
7. Create virtual environment
● You can use `venv` builtin module of Python.
○ `python3 -m venv my_virtualenv`
● Virtualenvwrapper
○ https://virtualenvwrapper.readthedocs.io/en/latest/
● Virtualenv
○ https://pypi.python.org/pypi/virtualenv
8. Make requirements.txt
● 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.
9. Create a website
● Create website first
○ django-admin startproject mysite
● Here, `mysite` is name of website.
● Mysite directory
● ├── manage.py
● ├── mysite
10. 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.
12. Blog Post model structure
● Title
● Text
● Create date
● Published
● Author
13. Adding fields to model
class Post(models.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)
def __str__(self):
return self.title
14. 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
16. Introduction to Django admin
● Django admin panel is for managing website
● Do not make it available to all the users
● You can customize it, but remember it is for admin
26. 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')
28. How to learn Django?
● Read tutorials section divided into 6 parts of Django
https://media.readthedocs.org/pdf/django/1.8.x/django.pdf
● 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