SlideShare una empresa de Scribd logo
1 de 61
Descargar para leer sin conexión
Django:
                         A Whirlwind Tour
                               Brad Montgomery

                           Email: brad@workforpie.com
                             Twitter: bkmontgomery




Friday, November 2, 12
Django: Features
                     • Python
                     • ORM: Object-Relational Mapper
                     • MVC-inspired (MVT)
                     • Clean URLs
                     • Huge Community
                     • Worlds Best Documentation
Friday, November 2, 12
Batteries Included
                              aka: contrib apps
                     • admin
                     • auth
                     • comments
                     • gis
                     • syndication (atom/rss feeds)
                     • sitemaps
Friday, November 2, 12
https://djangoproject.com/




Friday, November 2, 12
Community
                     • 3rd-party, open source apps
                     • django-registration
                     • django-social-auth
                     • django-taggit
                     • django-gravatar2
                     • django-relationships
Friday, November 2, 12
http://djangopackages.com/




Friday, November 2, 12
So, who’s actually using Django?




Friday, November 2, 12
Disqus,
                            Instagram,
                         Pintrest, Mozilla,
                         Rdio, Bitbucket,
                          Work for Pie,
                           GiantBomb,
                            The Onion
Friday, November 2, 12
Projects & Apps
                     • Projects are a collection of applications
                     • Settings
                      • DB Connections
                      • installed apps
                      • Filesystem paths
                     • Command-line tool: manage.py
Friday, November 2, 12
Projects & Apps

                         $ django-admin.py 
                              startproject 
                              sampleproject




Friday, November 2, 12
Projects & Apps
                         sampleproject/
                         !"" manage.py
                         #"" sampleproject
                             !"" __init__.py
                             !"" settings.py
                             !"" urls.py
                             #"" wsgi.py

Friday, November 2, 12
Projects & Apps

                         $ python manage.py 
                                  startapp blog




Friday, November 2, 12
Projects & Apps
                         sampleproject/
                         !"" blog
                             !"" __init__.py
                             !"" models.py
                             !"" tests.py
                             #"" views.py


Friday, November 2, 12
Models
             from django.db import models
             from django.contrib.auth.models import User


             class Post(models.Model):
                 author = models.ForeignKey(User)
                 title = models.CharField(max_length=128)
                 slug = models.SlugField(max_length=128, unique=True)
                 content = models.TextField()
                 published_on = models.DateTimeField(auto_now_add=True)



                         sampleproject/blog/models.py


Friday, November 2, 12
syncdb


                         $ python manage.py syncdb




Friday, November 2, 12
Views
                     from django.shortcuts import render_to_response
                     from django.template import RequestContext
                     from models import Post

                     def display_post(request, post_slug):
                         post = Post.objects.get(slug=post_slug)
                         template_data = {'post': post}
                         template = "blog/post.html"

                          return render_to_response(
                              template,
                              template_data,
                              context_instance=RequestContext(request)
                          )


                         sampleproject/blog/views.py

Friday, November 2, 12
Views
                     from django.shortcuts import render_to_response
                     from django.template import RequestContext
                     from models import Post

                     def display_post(request, post_slug):
                         post = Post.objects.get(slug=post_slug)
                         template_data = {'post': post}
                         template = "blog/post.html"

                          return render_to_response(
                              template,
                              template_data,
                              context_instance=RequestContext(request)
                          )


                         sampleproject/blog/views.py

Friday, November 2, 12
Views
                     from django.shortcuts import render_to_response
                     from django.template import RequestContext
                     from models import Post

                     def display_post(request, post_slug):
                         post = Post.objects.get(slug=post_slug)
                         template_data = {'post': post}
                         template = "blog/post.html"

                          return render_to_response(
                              template,
                              template_data,
                              context_instance=RequestContext(request)
                          )


                         sampleproject/blog/views.py

Friday, November 2, 12
Views
                     from django.shortcuts import render_to_response
                     from django.template import RequestContext
                     from models import Post

                     def display_post(request, post_slug):
                         post = Post.objects.get(slug=post_slug)
                         template_data = {'post': post}
                         template = "blog/post.html"

                          return render_to_response(
                              template,
                              template_data,
                              context_instance=RequestContext(request)
                          )


                         sampleproject/blog/views.py

Friday, November 2, 12
Views
                     from django.shortcuts import render_to_response
                     from django.template import RequestContext
                     from models import Post

                     def display_post(request, post_slug):
                         post = Post.objects.get(slug=post_slug)
                         template_data = {'post': post}
                         template = "blog/post.html"

                          return render_to_response(
                              template,
                              template_data,
                              context_instance=RequestContext(request)
                          )


                         sampleproject/blog/views.py

Friday, November 2, 12
Views
                     from django.shortcuts import render_to_response
                     from django.template import RequestContext
                     from models import Post

                     def display_post(request, post_slug):
                         post = Post.objects.get(slug=post_slug)
                         template_data = {'post': post}
                         template = "blog/post.html"

                          return render_to_response(
                              template,
                              template_data,
                              context_instance=RequestContext(request)
                          )


                         sampleproject/blog/views.py

Friday, November 2, 12
A base template
                             <!DOCTYPE html>
                             <html>
                             <head>
                                 <title>
                                 {% block title %}{% endblock %}
                                 </title>
                             </head>

                             <body>
                                 {% block content %}{% endblock %}
                             </body>
                             </html>


                         sampleproject/sampleproject/templates/base.html




Friday, November 2, 12
A base template
                             <!DOCTYPE html>
                             <html>
                             <head>
                                 <title>
                                 {% block title %}{% endblock %}
                                 </title>
                             </head>

                             <body>
                                 {% block content %}{% endblock %}
                             </body>
                             </html>


                         sampleproject/sampleproject/templates/base.html




Friday, November 2, 12
A post template
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html



Friday, November 2, 12
A post template
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html



Friday, November 2, 12
A post template
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html


Friday, November 2, 12
A post template
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html


Friday, November 2, 12
A post template
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html


Friday, November 2, 12
A post template
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html



Friday, November 2, 12
A post template
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html


Friday, November 2, 12
A post template
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html


Friday, November 2, 12
URL Conf’s

                     • Tie it all together!
                     • Route HTTP requests to views
                      • May also capture values



Friday, November 2, 12
Root URLConf
                         from django.conf.urls import patterns, include, url

                         from django.contrib import admin
                         admin.autodiscover()

                         urlpatterns = patterns('',
                             url(r'^blog/(?P<post_slug>.+)/$',
                                 'blog.views.display_post',
                                 name='display_post'),
                             url(r'^admin/', include(admin.site.urls)),
                         )



                    sampleproject/sampleproject/urls.py


Friday, November 2, 12
Root URLConf
                         from django.conf.urls import patterns, include, url

                         from django.contrib import admin
                         admin.autodiscover()

                         urlpatterns = patterns('',
                             url(r'^blog/(?P<post_slug>.+)/$',
                                 'blog.views.display_post',
                                 name='display_post'),
                             url(r'^admin/', include(admin.site.urls)),
                         )



                    sampleproject/sampleproject/urls.py


Friday, November 2, 12
Root URLConf
                         from django.conf.urls import patterns, include, url

                         from django.contrib import admin
                         admin.autodiscover()

                         urlpatterns = patterns('',
                             url(r'^blog/(?P<post_slug>.+)/$',
                                 'blog.views.display_post',
                                 name='display_post'),
                             url(r'^admin/', include(admin.site.urls)),
                         )



                    sampleproject/sampleproject/urls.py


Friday, November 2, 12
Root URLConf
                         from django.conf.urls import patterns, include, url

                         from django.contrib import admin
                         admin.autodiscover()

                         urlpatterns = patterns('',
                             url(r'^blog/(?P<post_slug>.+)/$',
                                 'blog.views.display_post',
                                 name='display_post'),
                             url(r'^admin/', include(admin.site.urls)),
                         )



                    sampleproject/sampleproject/urls.py


Friday, November 2, 12
Root URLConf
                         from django.conf.urls import patterns, include, url

                         from django.contrib import admin
                         admin.autodiscover()

                         urlpatterns = patterns('',
                             url(r'^blog/(?P<post_slug>.+)/$',
                                 'blog.views.display_post',
                                 name='display_post'),
                             url(r'^admin/', include(admin.site.urls)),
                         )



                    sampleproject/sampleproject/urls.py


Friday, November 2, 12
Root URLConf
                         from django.conf.urls import patterns, include, url

                         from django.contrib import admin
                         admin.autodiscover()

                         urlpatterns = patterns('',
                             url(r'^blog/(?P<post_slug>.+)/$',
                                 'blog.views.display_post',
                                 name='display_post'),
                             url(r'^admin/', include(admin.site.urls)),
                         )



                    sampleproject/sampleproject/urls.py


Friday, November 2, 12
An HTTP Request




Friday, November 2, 12
An HTTP Request




Friday, November 2, 12
An HTTP Request
                            blog/sample-title/
                         from django.conf.urls import patterns, include, url

                         from django.contrib import admin
                         admin.autodiscover()

                         urlpatterns = patterns('',
                             url(r'^blog/(?P<post_slug>.+)/$',
                                 'blog.views.display_post',
                                 name='display_post'),
                             url(r'^admin/', include(admin.site.urls)),
                         )



                    sampleproject/sampleproject/urls.py


Friday, November 2, 12
An HTTP Request
                            blog/sample-title/
                         from django.conf.urls import patterns, include, url

                         from django.contrib import admin
                         admin.autodiscover()

                         urlpatterns = patterns('',
                             url(r'^blog/(?P<post_slug>.+)/$',
                                 'blog.views.display_post',
                                 name='display_post'),
                             url(r'^admin/', include(admin.site.urls)),
                         )



                    sampleproject/sampleproject/urls.py


Friday, November 2, 12
An HTTP Request
                          sample-title
                     def display_post(request, post_slug):
                         post = Post.objects.get(slug=post_slug)
                         template_data = {'post': post}
                         template = "blog/post.html"

                          return render_to_response(
                              template,
                              template_data,
                              context_instance=RequestContext(request)
                          )


                         sampleproject/blog/views.py

Friday, November 2, 12
An HTTP Request
                         {% extends "base.html" %}        Sample Title
                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html



Friday, November 2, 12
An HTTP Request
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}                    Lorem Ipsum...
                         {% block content %}
                             <h1>{{ post.title }}</h1>

                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html



Friday, November 2, 12
An HTTP Request
                         {% extends "base.html" %}

                         {% block title %}
                             {{ post.title }}
                         {% endblock %}

                         {% block content %}
                             <h1>{{ post.title }}</h1>        Nov 3, 2012
                             {{ post.content|urlize|linebreaks }}

                             <p>Published on:
                                {{ post.published_on|date:"M d, Y" }}</p>
                         {% endblock %}


                         sampleproject/blog/templates/blog/post.html



Friday, November 2, 12
An HTTP Request




Friday, November 2, 12
Friday, November 2, 12
A Typical Stack




                                      Linux

Friday, November 2, 12
A Typical Stack




                           PostgreSQL
                                        Linux

Friday, November 2, 12
A Typical Stack


                          Gunicorn + Django



                             PostgreSQL
                                              Linux

Friday, November 2, 12
A Typical Stack
                                nginx


                          Gunicorn + Django



                             PostgreSQL
                                              Linux

Friday, November 2, 12
A Typical Stack
                              Varnish
                                             Memcached
                               nginx

                                             RabbitMQ
                         Gunicorn + Django


                                               Redis
                            PostgreSQL
                                                  Linux

Friday, November 2, 12
Friday, November 2, 12
Enter: Heroku

                     • Deploy & Scale in the Cloud
                     • Provides on-demand App/DB servers
                     • The Heroku Toolbelt
                     • http://www.heroku.com/

Friday, November 2, 12
Deploying to Heroku
                   Do a little bit of setup...
                     $ heroku create

                     Creating app-name... done, stack is cedar
                     http://app-name.herokuapp.com/ | git@heroku.com:app-name.git
                     Git remote heroku added




Friday, November 2, 12
Deploying to Heroku

                     $ git push heroku master

                         ... lots of output ...




Friday, November 2, 12
Deploying to Heroku

                     $ heroku run python manage.py syncdb

                     ... your typical syncdb output ...




Friday, November 2, 12
Deploying to Heroku
                   Develop locally, then when you want
                   to deploy, just run:

                     $ git push heroku master




Friday, November 2, 12
Want to Learn More?

                     •   Official Django Docs

                         •   https://docs.djangoproject.com

                     •   *Djangobook http://www.djangobook.com

                     •   Find Apps: http://www.djangopackages.com/

                     •   Coming Soon: http://gettingstartedwithdjango.com/




Friday, November 2, 12
Q.E.D.




Friday, November 2, 12

Más contenido relacionado

La actualidad más candente

Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web ApplicationsJames Da Costa
 
Django Performance Recipes
Django Performance RecipesDjango Performance Recipes
Django Performance RecipesJon Atkinson
 
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSHannes Hapke
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django frameworkflapiello
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Eric Palakovich Carr
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersRosario Renga
 
Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3makoto tsuyuki
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORMYaroslav Muravskyi
 
Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics PresentationShrinath Shenoy
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Djangocolinkingswood
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play NiceAlex Gaynor
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to ServicesCraig Kerstiens
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAEWinston Chen
 
Django multi-tier
Django multi-tierDjango multi-tier
Django multi-tiersmirolo
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012Nicholas Zakas
 

La actualidad más candente (20)

Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web Applications
 
Django Performance Recipes
Django Performance RecipesDjango Performance Recipes
Django Performance Recipes
 
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJS
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django framework
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3
 
Writing Pluggable Software
Writing Pluggable SoftwareWriting Pluggable Software
Writing Pluggable Software
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
 
Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics Presentation
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play Nice
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAE
 
Django multi-tier
Django multi-tierDjango multi-tier
Django multi-tier
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012
 
Django Documentation
Django DocumentationDjango Documentation
Django Documentation
 

Similar a Django a whirlwind tour

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1MicroPyramid .
 
Projeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfProjeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfAdrianoSantos888423
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talkdtdannen
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheetLam Hoang
 
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1makoto tsuyuki
 
Python, web scraping and content management: Scrapy and Django
Python, web scraping and content management: Scrapy and DjangoPython, web scraping and content management: Scrapy and Django
Python, web scraping and content management: Scrapy and DjangoSammy Fung
 
Data Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreData Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreRyan Morlok
 
Making the Most of Your Gradle Build
Making the Most of Your Gradle BuildMaking the Most of Your Gradle Build
Making the Most of Your Gradle BuildAndres Almiray
 
Django Overview
Django OverviewDjango Overview
Django OverviewBrian Tol
 
django_reference_sheet
django_reference_sheetdjango_reference_sheet
django_reference_sheetwebuploader
 
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribTzu-ping Chung
 
Dgeni documentation generator
Dgeni   documentation generatorDgeni   documentation generator
Dgeni documentation generatorPeter Darwin
 

Similar a Django a whirlwind tour (20)

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Grails 2.0 Update
Grails 2.0 UpdateGrails 2.0 Update
Grails 2.0 Update
 
Django
DjangoDjango
Django
 
Django - basics
Django - basicsDjango - basics
Django - basics
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1
 
templates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtratemplates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtra
 
Projeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfProjeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdf
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
 
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
スゴイ django - Python&Djangoで始めるWeb開発 in 札幌 #1
 
Django
DjangoDjango
Django
 
Python, web scraping and content management: Scrapy and Django
Python, web scraping and content management: Scrapy and DjangoPython, web scraping and content management: Scrapy and Django
Python, web scraping and content management: Scrapy and Django
 
Data Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreData Migrations in the App Engine Datastore
Data Migrations in the App Engine Datastore
 
Making the Most of Your Gradle Build
Making the Most of Your Gradle BuildMaking the Most of Your Gradle Build
Making the Most of Your Gradle Build
 
Django Overview
Django OverviewDjango Overview
Django Overview
 
django_reference_sheet
django_reference_sheetdjango_reference_sheet
django_reference_sheet
 
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
 
Dgeni documentation generator
Dgeni   documentation generatorDgeni   documentation generator
Dgeni documentation generator
 

Último

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
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
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
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
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
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
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
 

Último (20)

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
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
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...
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
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
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
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
 

Django a whirlwind tour

  • 1. Django: A Whirlwind Tour Brad Montgomery Email: brad@workforpie.com Twitter: bkmontgomery Friday, November 2, 12
  • 2. Django: Features • Python • ORM: Object-Relational Mapper • MVC-inspired (MVT) • Clean URLs • Huge Community • Worlds Best Documentation Friday, November 2, 12
  • 3. Batteries Included aka: contrib apps • admin • auth • comments • gis • syndication (atom/rss feeds) • sitemaps Friday, November 2, 12
  • 5. Community • 3rd-party, open source apps • django-registration • django-social-auth • django-taggit • django-gravatar2 • django-relationships Friday, November 2, 12
  • 7. So, who’s actually using Django? Friday, November 2, 12
  • 8. Disqus, Instagram, Pintrest, Mozilla, Rdio, Bitbucket, Work for Pie, GiantBomb, The Onion Friday, November 2, 12
  • 9. Projects & Apps • Projects are a collection of applications • Settings • DB Connections • installed apps • Filesystem paths • Command-line tool: manage.py Friday, November 2, 12
  • 10. Projects & Apps $ django-admin.py startproject sampleproject Friday, November 2, 12
  • 11. Projects & Apps sampleproject/ !"" manage.py #"" sampleproject !"" __init__.py !"" settings.py !"" urls.py #"" wsgi.py Friday, November 2, 12
  • 12. Projects & Apps $ python manage.py startapp blog Friday, November 2, 12
  • 13. Projects & Apps sampleproject/ !"" blog    !"" __init__.py    !"" models.py    !"" tests.py    #"" views.py Friday, November 2, 12
  • 14. Models from django.db import models from django.contrib.auth.models import User class Post(models.Model): author = models.ForeignKey(User) title = models.CharField(max_length=128) slug = models.SlugField(max_length=128, unique=True) content = models.TextField() published_on = models.DateTimeField(auto_now_add=True) sampleproject/blog/models.py Friday, November 2, 12
  • 15. syncdb $ python manage.py syncdb Friday, November 2, 12
  • 16. Views from django.shortcuts import render_to_response from django.template import RequestContext from models import Post def display_post(request, post_slug): post = Post.objects.get(slug=post_slug) template_data = {'post': post} template = "blog/post.html" return render_to_response( template, template_data, context_instance=RequestContext(request) ) sampleproject/blog/views.py Friday, November 2, 12
  • 17. Views from django.shortcuts import render_to_response from django.template import RequestContext from models import Post def display_post(request, post_slug): post = Post.objects.get(slug=post_slug) template_data = {'post': post} template = "blog/post.html" return render_to_response( template, template_data, context_instance=RequestContext(request) ) sampleproject/blog/views.py Friday, November 2, 12
  • 18. Views from django.shortcuts import render_to_response from django.template import RequestContext from models import Post def display_post(request, post_slug): post = Post.objects.get(slug=post_slug) template_data = {'post': post} template = "blog/post.html" return render_to_response( template, template_data, context_instance=RequestContext(request) ) sampleproject/blog/views.py Friday, November 2, 12
  • 19. Views from django.shortcuts import render_to_response from django.template import RequestContext from models import Post def display_post(request, post_slug): post = Post.objects.get(slug=post_slug) template_data = {'post': post} template = "blog/post.html" return render_to_response( template, template_data, context_instance=RequestContext(request) ) sampleproject/blog/views.py Friday, November 2, 12
  • 20. Views from django.shortcuts import render_to_response from django.template import RequestContext from models import Post def display_post(request, post_slug): post = Post.objects.get(slug=post_slug) template_data = {'post': post} template = "blog/post.html" return render_to_response( template, template_data, context_instance=RequestContext(request) ) sampleproject/blog/views.py Friday, November 2, 12
  • 21. Views from django.shortcuts import render_to_response from django.template import RequestContext from models import Post def display_post(request, post_slug): post = Post.objects.get(slug=post_slug) template_data = {'post': post} template = "blog/post.html" return render_to_response( template, template_data, context_instance=RequestContext(request) ) sampleproject/blog/views.py Friday, November 2, 12
  • 22. A base template <!DOCTYPE html> <html> <head> <title> {% block title %}{% endblock %} </title> </head> <body> {% block content %}{% endblock %} </body> </html> sampleproject/sampleproject/templates/base.html Friday, November 2, 12
  • 23. A base template <!DOCTYPE html> <html> <head> <title> {% block title %}{% endblock %} </title> </head> <body> {% block content %}{% endblock %} </body> </html> sampleproject/sampleproject/templates/base.html Friday, November 2, 12
  • 24. A post template {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 25. A post template {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 26. A post template {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 27. A post template {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 28. A post template {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 29. A post template {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 30. A post template {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 31. A post template {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 32. URL Conf’s • Tie it all together! • Route HTTP requests to views • May also capture values Friday, November 2, 12
  • 33. Root URLConf from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^blog/(?P<post_slug>.+)/$', 'blog.views.display_post', name='display_post'), url(r'^admin/', include(admin.site.urls)), ) sampleproject/sampleproject/urls.py Friday, November 2, 12
  • 34. Root URLConf from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^blog/(?P<post_slug>.+)/$', 'blog.views.display_post', name='display_post'), url(r'^admin/', include(admin.site.urls)), ) sampleproject/sampleproject/urls.py Friday, November 2, 12
  • 35. Root URLConf from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^blog/(?P<post_slug>.+)/$', 'blog.views.display_post', name='display_post'), url(r'^admin/', include(admin.site.urls)), ) sampleproject/sampleproject/urls.py Friday, November 2, 12
  • 36. Root URLConf from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^blog/(?P<post_slug>.+)/$', 'blog.views.display_post', name='display_post'), url(r'^admin/', include(admin.site.urls)), ) sampleproject/sampleproject/urls.py Friday, November 2, 12
  • 37. Root URLConf from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^blog/(?P<post_slug>.+)/$', 'blog.views.display_post', name='display_post'), url(r'^admin/', include(admin.site.urls)), ) sampleproject/sampleproject/urls.py Friday, November 2, 12
  • 38. Root URLConf from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^blog/(?P<post_slug>.+)/$', 'blog.views.display_post', name='display_post'), url(r'^admin/', include(admin.site.urls)), ) sampleproject/sampleproject/urls.py Friday, November 2, 12
  • 39. An HTTP Request Friday, November 2, 12
  • 40. An HTTP Request Friday, November 2, 12
  • 41. An HTTP Request blog/sample-title/ from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^blog/(?P<post_slug>.+)/$', 'blog.views.display_post', name='display_post'), url(r'^admin/', include(admin.site.urls)), ) sampleproject/sampleproject/urls.py Friday, November 2, 12
  • 42. An HTTP Request blog/sample-title/ from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^blog/(?P<post_slug>.+)/$', 'blog.views.display_post', name='display_post'), url(r'^admin/', include(admin.site.urls)), ) sampleproject/sampleproject/urls.py Friday, November 2, 12
  • 43. An HTTP Request sample-title def display_post(request, post_slug): post = Post.objects.get(slug=post_slug) template_data = {'post': post} template = "blog/post.html" return render_to_response( template, template_data, context_instance=RequestContext(request) ) sampleproject/blog/views.py Friday, November 2, 12
  • 44. An HTTP Request {% extends "base.html" %} Sample Title {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 45. An HTTP Request {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} Lorem Ipsum... {% block content %} <h1>{{ post.title }}</h1> {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 46. An HTTP Request {% extends "base.html" %} {% block title %} {{ post.title }} {% endblock %} {% block content %} <h1>{{ post.title }}</h1> Nov 3, 2012 {{ post.content|urlize|linebreaks }} <p>Published on: {{ post.published_on|date:"M d, Y" }}</p> {% endblock %} sampleproject/blog/templates/blog/post.html Friday, November 2, 12
  • 47. An HTTP Request Friday, November 2, 12
  • 49. A Typical Stack Linux Friday, November 2, 12
  • 50. A Typical Stack PostgreSQL Linux Friday, November 2, 12
  • 51. A Typical Stack Gunicorn + Django PostgreSQL Linux Friday, November 2, 12
  • 52. A Typical Stack nginx Gunicorn + Django PostgreSQL Linux Friday, November 2, 12
  • 53. A Typical Stack Varnish Memcached nginx RabbitMQ Gunicorn + Django Redis PostgreSQL Linux Friday, November 2, 12
  • 55. Enter: Heroku • Deploy & Scale in the Cloud • Provides on-demand App/DB servers • The Heroku Toolbelt • http://www.heroku.com/ Friday, November 2, 12
  • 56. Deploying to Heroku Do a little bit of setup... $ heroku create Creating app-name... done, stack is cedar http://app-name.herokuapp.com/ | git@heroku.com:app-name.git Git remote heroku added Friday, November 2, 12
  • 57. Deploying to Heroku $ git push heroku master ... lots of output ... Friday, November 2, 12
  • 58. Deploying to Heroku $ heroku run python manage.py syncdb ... your typical syncdb output ... Friday, November 2, 12
  • 59. Deploying to Heroku Develop locally, then when you want to deploy, just run: $ git push heroku master Friday, November 2, 12
  • 60. Want to Learn More? • Official Django Docs • https://docs.djangoproject.com • *Djangobook http://www.djangobook.com • Find Apps: http://www.djangopackages.com/ • Coming Soon: http://gettingstartedwithdjango.com/ Friday, November 2, 12