SlideShare a Scribd company logo
1 of 30
Tango with Django
By Jaysinh Shukla
Speaker Description
Self employed Pythonista
Github: http://github.com/ultimatecoder, http://github.com/jsh-odoo
Twitter: @jaysinhp
Emai: jaysinhp@gmail.com
IRC: thebigj
Blog: http://blog.jaysinh.com
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!
Benefits of Django
● Open source
● Large community base
● MVC
● Secure
● Fast Web application development
● Scalable
Who is using Django?
● Pinterest
● Instagram
● Mozilla
● Bitbucket
● NASA
● 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
Model
● Template part is used for combining model object with the HTML
templates
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
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.
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.
Start app
● Startapp
○ `python manage.py startapp blog`
● Mysite
● │ ├── admin.py
● │ ├── __init__.py
● │ ├── models.py
Blog Post model structure
● Title
● Text
● Create date
● Published
● Author
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
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
Introduction to Django contribution modules
● https://docs.djangoproject.com/en/1.8/ref/contrib/
● django.contrib.auth
● django.contrib.contenttypes
● django.contrib.sessions
● django.contrib.messages
● django.contrib.staticfiles
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
Createsuperuser
● `python manage.py createsuperuser`
● Super user has all the authority.
Django shell
● model.objects.all()
● model.objects.filter()
● model.objects.get()
○ model.DoesNotExists
● Chaining
● len()
Creating view
● A view where all the blog posts are displayed in one title
● A view where single blog post is viewed
Adding templates
● Create templates dir under application
○ Templates/blog/base.html
○ templates/blog/list.html
○ templates/blog/single.html
Base template
● <html>
● <head>
● <title>{% block title %} {% endblock %} </title>
● </head>
● <body>
● {% block body %} {% endblock %}
Single Post
● {% extends 'blog/base.html' %}
● {% block title %} {{ post.title }} {% endblock %}
● {% block body %}
● <table>
List view
● {% extends 'blog/base.html' %}
● {% block title %} List of blogposts {% endblock %}
● {% block body %}
● {% for post in posts %}
● <table><tr><td><a href="{% url 'single_post' post.id %}">{{ post.title }}</a>
</td></tr>
Type of views
● Function based views
● Class based views
● Built in views
Understanding Regex
● ^
● $
● ()
● ?P
● <variable_name>
● https://docs.python.org/3.4/library/re.html
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')
Creating views
● def single_post(request, post_id):
● try:
● post = Post.objects.get(id=post_id)
● except Post.DoesNotExists:
● return Http404("Post didn't found")
● return render(request, 'blog/post.html', {'post': post})
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
Feedback
https://goo.gl/forms/YIqstv2
cmoyLjZul2
Q & A

More Related Content

What's hot

Word press beirut December 4 Meetup - Gutenberg VS WP-Bakery
Word press beirut December 4 Meetup - Gutenberg VS WP-Bakery Word press beirut December 4 Meetup - Gutenberg VS WP-Bakery
Word press beirut December 4 Meetup - Gutenberg VS WP-Bakery Fadi Nicolas Zahhar
 
moma-django overview --> Django + MongoDB: building a custom ORM layer
moma-django overview --> Django + MongoDB: building a custom ORM layermoma-django overview --> Django + MongoDB: building a custom ORM layer
moma-django overview --> Django + MongoDB: building a custom ORM layerGadi Oren
 
Introduction to Javascript - College Lecture
Introduction to Javascript - College LectureIntroduction to Javascript - College Lecture
Introduction to Javascript - College LectureZac Gordon
 

What's hot (6)

App Engine
App EngineApp Engine
App Engine
 
Word press beirut December 4 Meetup - Gutenberg VS WP-Bakery
Word press beirut December 4 Meetup - Gutenberg VS WP-Bakery Word press beirut December 4 Meetup - Gutenberg VS WP-Bakery
Word press beirut December 4 Meetup - Gutenberg VS WP-Bakery
 
Web Component
Web ComponentWeb Component
Web Component
 
Learn TypeScript from scratch
Learn TypeScript from scratchLearn TypeScript from scratch
Learn TypeScript from scratch
 
moma-django overview --> Django + MongoDB: building a custom ORM layer
moma-django overview --> Django + MongoDB: building a custom ORM layermoma-django overview --> Django + MongoDB: building a custom ORM layer
moma-django overview --> Django + MongoDB: building a custom ORM layer
 
Introduction to Javascript - College Lecture
Introduction to Javascript - College LectureIntroduction to Javascript - College Lecture
Introduction to Javascript - College Lecture
 

Similar to Django Web Framework Basics

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoKnoldus Inc.
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoAhmed Salama
 
Django best practices
Django best practicesDjango best practices
Django best practicesAdam Haney
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingAlessandro Molina
 
Django tutorial
Django tutorialDjango tutorial
Django tutorialKsd Che
 
Learn Django Tips, Tricks & Techniques for Developers
Learn Django Tips, Tricks & Techniques for DevelopersLearn Django Tips, Tricks & Techniques for Developers
Learn Django Tips, Tricks & Techniques for DevelopersMars Devs
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and ArchitectureAndolasoft Inc
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| EdurekaEdureka!
 
[JogjaJS] Single Page Application nganggo Angular.js
[JogjaJS] Single Page Application nganggo Angular.js [JogjaJS] Single Page Application nganggo Angular.js
[JogjaJS] Single Page Application nganggo Angular.js Yanuar W
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsQing-Cheng Li
 
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...Alessandro Molina
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)Nishant Soni
 
Creating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressCreating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressHristo Chakarov
 

Similar to Django Web Framework Basics (20)

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Django best practices
Django best practicesDjango best practices
Django best practices
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Learn Django Tips, Tricks & Techniques for Developers
Learn Django Tips, Tricks & Techniques for DevelopersLearn Django Tips, Tricks & Techniques for Developers
Learn Django Tips, Tricks & Techniques for Developers
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| Edureka
 
React django
React djangoReact django
React django
 
[JogjaJS] Single Page Application nganggo Angular.js
[JogjaJS] Single Page Application nganggo Angular.js [JogjaJS] Single Page Application nganggo Angular.js
[JogjaJS] Single Page Application nganggo Angular.js
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser Extensions
 
Django by rj
Django by rjDjango by rj
Django by rj
 
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)
 
Creating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressCreating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPress
 

Recently uploaded

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 

Recently uploaded (20)

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 

Django Web Framework Basics

  • 1. Tango with Django By Jaysinh Shukla
  • 2. Speaker Description Self employed Pythonista Github: http://github.com/ultimatecoder, http://github.com/jsh-odoo Twitter: @jaysinhp Emai: jaysinhp@gmail.com IRC: thebigj Blog: http://blog.jaysinh.com
  • 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.
  • 11. Start app ● Startapp ○ `python manage.py startapp blog` ● Mysite ● │ ├── admin.py ● │ ├── __init__.py ● │ ├── models.py
  • 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
  • 15. Introduction to Django contribution modules ● https://docs.djangoproject.com/en/1.8/ref/contrib/ ● django.contrib.auth ● django.contrib.contenttypes ● django.contrib.sessions ● django.contrib.messages ● django.contrib.staticfiles
  • 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
  • 17. Createsuperuser ● `python manage.py createsuperuser` ● Super user has all the authority.
  • 18. Django shell ● model.objects.all() ● model.objects.filter() ● model.objects.get() ○ model.DoesNotExists ● Chaining ● len()
  • 19. Creating view ● A view where all the blog posts are displayed in one title ● A view where single blog post is viewed
  • 20. Adding templates ● Create templates dir under application ○ Templates/blog/base.html ○ templates/blog/list.html ○ templates/blog/single.html
  • 21. Base template ● <html> ● <head> ● <title>{% block title %} {% endblock %} </title> ● </head> ● <body> ● {% block body %} {% endblock %}
  • 22. Single Post ● {% extends 'blog/base.html' %} ● {% block title %} {{ post.title }} {% endblock %} ● {% block body %} ● <table>
  • 23. List view ● {% extends 'blog/base.html' %} ● {% block title %} List of blogposts {% endblock %} ● {% block body %} ● {% for post in posts %} ● <table><tr><td><a href="{% url 'single_post' post.id %}">{{ post.title }}</a> </td></tr>
  • 24. Type of views ● Function based views ● Class based views ● Built in views
  • 25. Understanding Regex ● ^ ● $ ● () ● ?P ● <variable_name> ● https://docs.python.org/3.4/library/re.html
  • 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')
  • 27. Creating views ● def single_post(request, post_id): ● try: ● post = Post.objects.get(id=post_id) ● except Post.DoesNotExists: ● return Http404("Post didn't found") ● return render(request, 'blog/post.html', {'post': 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
  • 30. Q & A