SlideShare a Scribd company logo
1 of 41
An Introduction ,[object Object],[object Object]
Django Reinhardt
ljworld.com
 
www.djangoproject.com
 
 
 
Overview of this Tutorial ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Django's Mission Statement ,[object Object]
Django Requirements ,[object Object],[object Object],[object Object]
“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>+)/$', 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 ,[object Object],[object Object],[object Object]
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

What's hot

Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django frameworkKnoldus Inc.
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Edureka!
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC FrameworkBala Kumar
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application StructureSEONGTAEK OH
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersRosario Renga
 
Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Edureka!
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python MeetupAreski Belaid
 
Django Interview Questions and Answers
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and AnswersPython Devloper
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django frameworkflapiello
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 

What's hot (20)

django
djangodjango
django
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Django
DjangoDjango
Django
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django framework
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
DJango
DJangoDJango
DJango
 
Django PPT.pptx
Django PPT.pptxDjango PPT.pptx
Django PPT.pptx
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
 
Django Interview Questions and Answers
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and Answers
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django framework
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 

Viewers also liked

The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application FrameworkSimon Willison
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Getting Started With Django
Getting Started With DjangoGetting Started With Django
Getting Started With Djangojeff_croft
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best PracticesDavid Arcos
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 
Starters with Django
Starters with Django Starters with Django
Starters with Django BeDjango
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Django nutshell overview
Django nutshell overviewDjango nutshell overview
Django nutshell overviewschacki
 
Django & Buildout
Django & BuildoutDjango & Buildout
Django & Buildoutzerok
 
Django shop
Django shopDjango shop
Django shopTribaal
 

Viewers also liked (18)

Django introduction
Django introductionDjango introduction
Django introduction
 
The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application Framework
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Getting Started With Django
Getting Started With DjangoGetting Started With Django
Getting Started With Django
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Free django
Free djangoFree django
Free django
 
Starters with Django
Starters with Django Starters with Django
Starters with Django
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Django Best Practices
Django Best PracticesDjango Best Practices
Django Best Practices
 
Python/Django Training
Python/Django TrainingPython/Django Training
Python/Django Training
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
dJango
dJangodJango
dJango
 
Django nutshell overview
Django nutshell overviewDjango nutshell overview
Django nutshell overview
 
Django & Buildout
Django & BuildoutDjango & Buildout
Django & Buildout
 
Django shop
Django shopDjango shop
Django shop
 
Why Django
Why DjangoWhy Django
Why Django
 

Similar to Django for Beginners

Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesLeonardo Fernandes
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Django for mobile applications
Django for mobile applicationsDjango for mobile applications
Django for mobile applicationsHassan Abid
 
DJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDamien Raczy
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimMir Nazim
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030Kevin Wu
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosIgor Sobreira
 

Similar to Django for Beginners (20)

Django
DjangoDjango
Django
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico Ces
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django
DjangoDjango
Django
 
Django for mobile applications
Django for mobile applicationsDjango for mobile applications
Django for mobile applications
 
Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
DJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptx
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
Django web framework
Django web frameworkDjango web framework
Django web framework
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Django tricks (2)
Django tricks (2)Django tricks (2)
Django tricks (2)
 
React django
React djangoReact django
React django
 
Django
DjangoDjango
Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
Django crush course
Django crush course Django crush course
Django crush course
 

Recently uploaded

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Django for Beginners

  • 1.
  • 4.  
  • 6.  
  • 7.  
  • 8.  
  • 9.
  • 10.
  • 11.
  • 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>+)/$', 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.
  • 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

  1. 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.