SlideShare a Scribd company logo
An Introduction Jason Davies PyCon UK 2007
Django Reinhardt
ljworld.com
 
www.djangoproject.com
 
 
 
Overview of this Tutorial Brief introduction and philosophy Creating Django models The automatic admin interface Views (and URLs) Templates Comparison with other frameworks
Django's Mission Statement “Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.”
Django Requirements Python (2.3+) PostgreSQL / MySQL / SQLite / ... Apache + mod_python / FastCGI / ...
“Projects” $ django-admin.py startproject myproject
myproject/ __init__.py manage.py settings.py urls.py
$ ./manage.py runserver Validating models... 0 errors found. Django version 0.96-pre, using settings 'myproject.settings' Development server is running at  http://127.0.0.1:8000/ Quit the server with CONTROL-C.
 
“Apps” $ django-admin.py startapp blog
myproject/ blog/ __init__.py models.py views.py __init__.py manage.py settings.py urls.py
Creating Models from django.db import models class Blog(models.Model): title = models.CharField(maxlength=200) class Post(models.Model): title = models.CharField(maxlength=200) body = models.TextField() blog = models.ForeignKey(Blog) pub_date = models.DateTimeField()
Activating Models $ ./manage.py syncdb Creating table blog_blog Creating table blog_post Loading 'initial_data' fixtures... No fixtures found.
Activating the Admin Interface from django.db import models class Blog(models.Model): title = models.CharField(maxlength=200) class Admin: list_display = ['title'] class Post(models.Model): title = models.CharField(maxlength=200) body = models.TextField() blog = models.ForeignKey(Blog) pub_date = models.DateTimeField() class Admin: list_display = ['title', 'pub_date']
 
 
Model API $ ./manage.py shell >>> from myproject.blog import Blog >>> b = Blog( ...  title=”Jason's Fantastic Blog!!!”) >>> b.save()
>>> all_blogs = Blog.objects.all() >>> print all_blogs [<Blog: Blog object>] >>> print all_blogs.name Jason's Fantastic Blog!!! >>> b = Blog.objects.get(name__contains='Jason') >>> print b.title Jason's Fantastic Blog!!!
URLs ROOT_URLCONF = 'myproject.urls'
URLconfs from django.conf.urls.defaults import * from myproject.blog.views import * urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls')), (r'^blog/$',  post_list), (r'^blog/(?P<id>\d+)/$', post_list), )
Views from django.http import HttpResponse def post_list(request): return HttpReponse(“This is a list of posts!”)
from django.http import HttpResponse from myproject.blog.models import Post def post_list(request): r = “<ul>” posts = Post.objects.order_by(“-pub_date”) for post in posts: r += “<li>%s: %s</li>” % (post.title, post.body) r += “</ul>” return HttpResponse(r) More realistic...
from django.shorcuts import render_to_response from myproject.blog.models import Post def post_list(request): posts = Post.objects.order_by(“-pub_date”) return render_to_response('blog/post_list.html', { 'post_list': posts, }) Better!
from django.shorcuts import render_to_response from myproject.blog.models import Post def post_detail(request, id): post = get_object_or_404(Post, id=id) return render_to_response('blog/post_detail.html', { 'post': post, }) For completeness...
Templates <html> <body> <h1>Jason's Fantastic Blog!!!</h1> <ul> {% for p in post_list %} <li> <a href=”{{ p.id }}/”>{{ p.title|escape }}</a> </li> {% endfor %} </ul> </body> </html>
The magic dot p[“name”] p.name p.name()
Filters {{ var|escape|linebreaks|... }}
base.html <html> <head> <title>{% block title %}{% endblock %} </head> <body> <div id=”content”> {% block content %}{% endblock %} </div> <div id=”footer”> {% block footer %} Copyright Jason Davies 2007. {% endblock %} </div> </body> </html>
{% extends “base.html” %} {% block title %} Posts | {{ block.super }} {% endblock %} {% block content %} <h1>Blog Posts ({{ post_list|length }} total)</h1> <ul> {% for post in post_list %} <li> <a href=”{{ post.id }}/”> {{ post.title|escape }} </a> </li> {% endfor %} </ul> {% endblock %}
Ruby on Rails http://www.rubyonrails.org/
http://www.alrond.com/en/2007/jan/25/performance-test-of-6-leading-frameworks/
Thank you for listening. Jason Davies [email_address] http://www.jasondavies.com/
http://www.mercurytide.co.uk/whitepapers/django-cheat-sheet/
 
 

More Related Content

PPTX
Web development with django - Basics Presentation
KEY
Introduction to Django
PDF
A Basic Django Introduction
PPTX
Django - Python MVC Framework
PDF
Web Development with Python and Django
PDF
Django Introduction & Tutorial
PPTX
Introduction to Django
PPT
Introduction To Django
Web development with django - Basics Presentation
Introduction to Django
A Basic Django Introduction
Django - Python MVC Framework
Web Development with Python and Django
Django Introduction & Tutorial
Introduction to Django
Introduction To Django

What's hot (20)

PPT
Django, What is it, Why is it cool?
PDF
Introduction to django
PPTX
Django Girls Tutorial
PPTX
Angular Data Binding
PDF
Python Django tutorial | Getting Started With Django | Web Development With D...
PPTX
Django Framework Overview forNon-Python Developers
PDF
Introduction to django framework
PDF
Angular - Chapter 7 - HTTP Services
PPT
DJango
KEY
Introduction Django
PDF
Python/Django Training
PPTX
Introduction to angular with a simple but complete project
PPTX
The Django Web Application Framework 2
PPTX
Spring Boot and REST API
PPTX
PDF
JavaScript - Chapter 3 - Introduction
PPTX
PPTX
Flask – Python
ODP
Routing & Navigating Pages in Angular 2
PDF
Angular - Chapter 1 - Introduction
Django, What is it, Why is it cool?
Introduction to django
Django Girls Tutorial
Angular Data Binding
Python Django tutorial | Getting Started With Django | Web Development With D...
Django Framework Overview forNon-Python Developers
Introduction to django framework
Angular - Chapter 7 - HTTP Services
DJango
Introduction Django
Python/Django Training
Introduction to angular with a simple but complete project
The Django Web Application Framework 2
Spring Boot and REST API
JavaScript - Chapter 3 - Introduction
Flask – Python
Routing & Navigating Pages in Angular 2
Angular - Chapter 1 - Introduction
Ad

Viewers also liked (17)

PPT
Django introduction
PDF
The Django Web Application Framework
PDF
Building a Dynamic Website Using Django
PDF
Getting Started With Django
PDF
Django in the Real World
PDF
12 tips on Django Best Practices
PPT
Introduction to Python
PDF
Free django
PDF
Starters with Django
PDF
The Best (and Worst) of Django
PDF
Django Best Practices
PDF
Learn 90% of Python in 90 Minutes
ODP
dJango
PDF
Django nutshell overview
PDF
Django & Buildout
ODP
Django shop
PDF
Why Django
Django introduction
The Django Web Application Framework
Building a Dynamic Website Using Django
Getting Started With Django
Django in the Real World
12 tips on Django Best Practices
Introduction to Python
Free django
Starters with Django
The Best (and Worst) of Django
Django Best Practices
Learn 90% of Python in 90 Minutes
dJango
Django nutshell overview
Django & Buildout
Django shop
Why Django
Ad

Similar to Django for Beginners (20)

PDF
Django 1.10.3 Getting started
PDF
PPT
Mini Curso Django Ii Congresso Academico Ces
PDF
django
PDF
Django workshop : let's make a blog
PDF
Introduction to Django
PDF
Django
PDF
Mini Curso de Django
ODP
Django tech-talk
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
ODP
Introduction to Django
PPTX
Tango with django
PDF
Django design-patterns
PPTX
Discovering Django - zekeLabs
PDF
Chapter 6 the django admin site
PPTX
Django course
PDF
PPT
Django for n00bs
Django 1.10.3 Getting started
Mini Curso Django Ii Congresso Academico Ces
django
Django workshop : let's make a blog
Introduction to Django
Django
Mini Curso de Django
Django tech-talk
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
Introduction to Django
Tango with django
Django design-patterns
Discovering Django - zekeLabs
Chapter 6 the django admin site
Django course
Django for n00bs

Recently uploaded (20)

PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
PDF
DevOps & Developer Experience Summer BBQ
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Event Presentation Google Cloud Next Extended 2025
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
This slide provides an overview Technology
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
creating-agentic-ai-solutions-leveraging-aws.pdf
PDF
SparkLabs Primer on Artificial Intelligence 2025
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PPTX
CroxyProxy Instagram Access id login.pptx
ChatGPT's Deck on The Enduring Legacy of Fax Machines
DevOps & Developer Experience Summer BBQ
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
NewMind AI Weekly Chronicles - July'25 - Week IV
agentic-ai-and-the-future-of-autonomous-systems.pdf
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
Transforming Manufacturing operations through Intelligent Integrations
Automating ArcGIS Content Discovery with FME: A Real World Use Case
NewMind AI Weekly Chronicles - August'25 Week I
Event Presentation Google Cloud Next Extended 2025
NewMind AI Monthly Chronicles - July 2025
This slide provides an overview Technology
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
creating-agentic-ai-solutions-leveraging-aws.pdf
SparkLabs Primer on Artificial Intelligence 2025
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
CroxyProxy Instagram Access id login.pptx

Django for Beginners

  • 1. An Introduction Jason Davies PyCon UK 2007
  • 4.  
  • 6.  
  • 7.  
  • 8.  
  • 9. Overview of this Tutorial Brief introduction and philosophy Creating Django models The automatic admin interface Views (and URLs) Templates Comparison with other frameworks
  • 10. Django's Mission Statement “Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.”
  • 11. Django Requirements Python (2.3+) PostgreSQL / MySQL / SQLite / ... Apache + mod_python / FastCGI / ...
  • 12. “Projects” $ django-admin.py startproject myproject
  • 13. myproject/ __init__.py manage.py settings.py urls.py
  • 14. $ ./manage.py runserver Validating models... 0 errors found. Django version 0.96-pre, using settings 'myproject.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
  • 15.  
  • 17. myproject/ blog/ __init__.py models.py views.py __init__.py manage.py settings.py urls.py
  • 18. Creating Models from django.db import models class Blog(models.Model): title = models.CharField(maxlength=200) class Post(models.Model): title = models.CharField(maxlength=200) body = models.TextField() blog = models.ForeignKey(Blog) pub_date = models.DateTimeField()
  • 19. Activating Models $ ./manage.py syncdb Creating table blog_blog Creating table blog_post Loading 'initial_data' fixtures... No fixtures found.
  • 20. Activating the Admin Interface from django.db import models class Blog(models.Model): title = models.CharField(maxlength=200) class Admin: list_display = ['title'] class Post(models.Model): title = models.CharField(maxlength=200) body = models.TextField() blog = models.ForeignKey(Blog) pub_date = models.DateTimeField() class Admin: list_display = ['title', 'pub_date']
  • 21.  
  • 22.  
  • 23. Model API $ ./manage.py shell >>> from myproject.blog import Blog >>> b = Blog( ... title=”Jason's Fantastic Blog!!!”) >>> b.save()
  • 24. >>> all_blogs = Blog.objects.all() >>> print all_blogs [<Blog: Blog object>] >>> print all_blogs.name Jason's Fantastic Blog!!! >>> b = Blog.objects.get(name__contains='Jason') >>> print b.title Jason's Fantastic Blog!!!
  • 25. URLs ROOT_URLCONF = 'myproject.urls'
  • 26. URLconfs from django.conf.urls.defaults import * from myproject.blog.views import * urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls')), (r'^blog/$', post_list), (r'^blog/(?P<id>\d+)/$', post_list), )
  • 27. Views from django.http import HttpResponse def post_list(request): return HttpReponse(“This is a list of posts!”)
  • 28. from django.http import HttpResponse from myproject.blog.models import Post def post_list(request): r = “<ul>” posts = Post.objects.order_by(“-pub_date”) for post in posts: r += “<li>%s: %s</li>” % (post.title, post.body) r += “</ul>” return HttpResponse(r) More realistic...
  • 29. from django.shorcuts import render_to_response from myproject.blog.models import Post def post_list(request): posts = Post.objects.order_by(“-pub_date”) return render_to_response('blog/post_list.html', { 'post_list': posts, }) Better!
  • 30. from django.shorcuts import render_to_response from myproject.blog.models import Post def post_detail(request, id): post = get_object_or_404(Post, id=id) return render_to_response('blog/post_detail.html', { 'post': post, }) For completeness...
  • 31. Templates <html> <body> <h1>Jason's Fantastic Blog!!!</h1> <ul> {% for p in post_list %} <li> <a href=”{{ p.id }}/”>{{ p.title|escape }}</a> </li> {% endfor %} </ul> </body> </html>
  • 32. The magic dot p[“name”] p.name p.name()
  • 34. base.html <html> <head> <title>{% block title %}{% endblock %} </head> <body> <div id=”content”> {% block content %}{% endblock %} </div> <div id=”footer”> {% block footer %} Copyright Jason Davies 2007. {% endblock %} </div> </body> </html>
  • 35. {% extends “base.html” %} {% block title %} Posts | {{ block.super }} {% endblock %} {% block content %} <h1>Blog Posts ({{ post_list|length }} total)</h1> <ul> {% for post in post_list %} <li> <a href=”{{ post.id }}/”> {{ post.title|escape }} </a> </li> {% endfor %} </ul> {% endblock %}
  • 36. Ruby on Rails http://www.rubyonrails.org/
  • 38. Thank you for listening. Jason Davies [email_address] http://www.jasondavies.com/
  • 40.  
  • 41.  

Editor's Notes

  • #2: Hello! My name is Jason Davies; I&apos;m a freelance Web developer from Cambridge and I&apos;ve been using Django for about 2 years ever since it was open-sourced in July 2005. Hopefully this will give you a good introduction to the basics of Django. Simon Willison will cover even more stuff in the advanced tutorial.