Jumpstart Django

5,155
-1

Published on

An overview of the Django rapid application development framework. Topics include the history of the framework, an architectural overview, how to get started, and a brief comparison to Ruby on Rails.

Published in: Technology, Business
0 Comments
16 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,155
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
237
Comments
0
Likes
16
Embeds 0
No embeds

No notes for slide
  • Survey: How many do web application development; in django; in rails
  • Lawrence, Kansas
    Since 1850’s
    Family run newspaper - currently run by someone who is 70 years old that does not use a computer - assistant prints out e-mails
  • Adrian: Chicago Crime, Coined the term “Database Journalism”
    Simon: Early work is part of many JS frameworks, Consultant on OpenID
    Joined by Jacob Kaplan-Moss
  • First online newspaper of it’s kind.
    Had a print edition of the website
  • “The CMS”
  • In a landscape of confusion - invent your own
  • Re-framed the perception of web development;
  • Various layers shouldn’t know about eachother unless absolutely necessary
    Code should lack boilerplate - Java
    Make tedious aspects fast - it’s just Python
    shouldn’t do much magic
  • Various layers shouldn’t know about eachother unless absolutely necessary
    Code should lack boilerplate - Java
    Make tedious aspects fast - it’s just Python
    shouldn’t do much magic
  • Various layers shouldn’t know about eachother unless absolutely necessary
    Code should lack boilerplate - Java
    Make tedious aspects fast - it’s just Python
    shouldn’t do much magic
  • Various layers shouldn’t know about eachother unless absolutely necessary
    Code should lack boilerplate - Java
    Make tedious aspects fast - it’s just Python
    shouldn’t do much magic
  • Various layers shouldn’t know about eachother unless absolutely necessary
    Code should lack boilerplate - Java
    Make tedious aspects fast - it’s just Python
    shouldn’t do much magic
  • Various layers shouldn’t know about eachother unless absolutely necessary
    Code should lack boilerplate - Java
    Make tedious aspects fast - it’s just Python
    shouldn’t do much magic
  • manage.py syncdb
  • Those too hip for non-relational databases will have to wait.
    Multi-DB support is coming.
  • Notice: more declarative programming
  • Notice: more declarative programming
  • You can generate these things dynamically
  • Middleware
  • Middleware
  • Middleware
  • Complete separation of logic and presentation - pain for things like Math or comparisons.
    Templates don’t need to be HTML - JSON, e-mail, text
  • Complete separation of logic and presentation - pain for things like Math or comparisons.
    Templates don’t need to be HTML - JSON, e-mail, text
  • Complete separation of logic and presentation - pain for things like Math or comparisons.
    Templates don’t need to be HTML - JSON, e-mail, text
  • Complete separation of logic and presentation - pain for things like Math or comparisons.
    Templates don’t need to be HTML - JSON, e-mail, text
  • PHP comparison doesn’t count.
    Really a Django Rails comparison
  • Who is the clear winner?
  • Curl.com
  • Curl.com
  • Curl.com
  • Curl.com
  • Curl.com
  • Curl.com
  • Jumpstart Django

    1. 1. Jumpstart The Web Framework for Perfectionists with Deadlines CPOSC Rob Yates October, 2009
    2. 2. Topics
    3. 3. Topics • What is Django
    4. 4. Topics • What is Django • History of Django
    5. 5. Topics • What is Django • History of Django • Whirlwind Tour
    6. 6. Topics • What is Django • History of Django • Whirlwind Tour • How to Get Started - Admin Demo
    7. 7. Topics • What is Django • History of Django • Whirlwind Tour • How to Get Started - Admin Demo • Killer Features
    8. 8. Topics • What is Django • History of Django • Whirlwind Tour • How to Get Started - Admin Demo • Killer Features • Application Re-use and Pinax
    9. 9. Topics • What is Django • History of Django • Whirlwind Tour • How to Get Started - Admin Demo • Killer Features • Application Re-use and Pinax • Framework Death-match
    10. 10. What is Django?
    11. 11. What is Django? • Not a Gypsy Jazz Guitarist
    12. 12. What is Django? • Not a Gypsy Jazz Guitarist • Web Application Development Framework written in and for Python
    13. 13. What is Django? • Not a Gypsy Jazz Guitarist • Web Application Development Framework written in and for Python • Not a CMS System
    14. 14. What is Django? • Not a Gypsy Jazz Guitarist • Web Application Development Framework written in and for Python • Not a CMS System • Sometimes called Python’s Ruby on Rails (RoR)
    15. 15. It all started HERE Photo by Jeff Croft
    16. 16. Simon Willison Adrian Holovaty
    17. 17. PyCon 2005 Major topic: Why is web development in Python so hard?
    18. 18. Jump to today: Guiding Principles
    19. 19. Jump to today: Guiding Principles • Loose Coupling and tight cohesion
    20. 20. Jump to today: Guiding Principles • Loose Coupling and tight cohesion • Less code
    21. 21. Jump to today: Guiding Principles • Loose Coupling and tight cohesion • Less code • Quick development
    22. 22. Jump to today: Guiding Principles • Loose Coupling and tight cohesion • Less code • Quick development • DRY
    23. 23. Jump to today: Guiding Principles • Loose Coupling and tight cohesion • Less code • Quick development • DRY • Explicit is better than implicit
    24. 24. Jump to today: Guiding Principles • Loose Coupling and tight cohesion • Less code • Quick development • DRY • Explicit is better than implicit • Consistency
    25. 25. For Free!!! • Very Useful Admin CRUD • Templating - lots of useful rendering bits • Form Handling • i18n - full Unicode support • Sessions / User Auth / Role-based Perms • Object-Relational Mapping Beer photo by Lori Spindler
    26. 26. Model View Controller
    27. 27. Model View Controller Model View Template
    28. 28. Models Templates App Views Models Templates App Views Site Models Templates App Views Settings URLs Django App Structure Templates
    29. 29. Architecture RDBMS Storage ORM Fixtures Model Signals Forms Template URL Resolver View Template Loader Middleware Middleware Request Response
    30. 30. Deep Dive: Models from tagging.fields import TagField class Post(models.Model): author = models.ForeignKey(Author) title = models.CharField(max_length=200) slug = models.SlugField(max_length=200, unique_for_month='pub_date') body = models.TextField() TYPE_CHOICES = ( ('rant', 'Rant'), ('tirade', 'Tirade'), ) type = models.CharField(choices=TYPE_CHOICES, max_length=50) pub_date = models.DateTimeField(auto_now_add=True) is_active = models.BooleanField(default=True) tags = TagField(blank=True, null=True) class Meta: unique_together = ('title', 'type') ordering = ['-pub_date']
    31. 31. Architecture RDBMS Storage ORM Fixtures Model Signals Forms Template URL Resolver View Template Loader Middleware Middleware Request Response
    32. 32. Deep Dive: DB API post = Post(title=‘Foo’, body=‘Bar’) post.type = ‘rant’ post.save()
    33. 33. Deep Dive: DB API post = Post(title=‘Foo’, body=‘Bar’) post.type = ‘rant’ post.save() posts = Post.objects.all() posts = Post.objects.all()[:5] posts = Post.objects.filter(post_type=‘rant’) posts = Post.objects.filter(author__name=‘Rob’) posts = Post.objects.filter(author__name=‘Rob’). filter(title__contains=‘django’).order_by(‘type’) post = Post.objects.get(id=24)
    34. 34. Architecture RDBMS Storage ORM Fixtures Model Signals Forms Template URL Resolver View Template Loader Middleware Middleware Request Response
    35. 35. Deep Dive: Forms # Basic Form class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() sender = forms.EmailField() cc_myself = forms.BooleanField(required=False)
    36. 36. Deep Dive: Forms # Basic Form class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() sender = forms.EmailField() cc_myself = forms.BooleanField(required=False) # Form based on a model class PostForm(forms.ModelForm): class Meta: model = Post
    37. 37. Deep Dive: Views def posts_by_type(request, type): posts = Post.objects.filter(type=type) return render_to_response( ‘postsbytype.html’, {‘posts’: posts})
    38. 38. Deep Dive: Views def posts_by_type(request, type): posts = Post.objects.filter(type=type) return render_to_response( ‘postsbytype.html’, {‘posts’: posts}) def new_post(request): if request.method == ‘POST’: form = PostForm(request.POST) if form.is_valid(): form.save() else: form = PostForm() return render_to_response( ‘mytemplate.html’, {‘form’: form})
    39. 39. Architecture RDBMS Storage ORM Fixtures Model Signals Forms Template URL Resolver View Template Loader Middleware Middleware Request Response
    40. 40. Deep Dive: URLs urlpatters = patterns(‘’, (’^my/favorite/color/$’, ‘blog.views.my_fav_color’), (‘^post/new/$’, ‘blog.views.new_post’), (‘^posts/(d{4})/$’, ‘blog.views.year_archive’), (‘^posts/(d{4})/(d{2})/$’, ‘blog.views.month_archive’), (‘^posts/(?P<slug>[a-z-]*)/$’, ‘blog.views.show_post’), (‘^events/$’, include(events.urls), )
    41. 41. Architecture RDBMS Storage ORM Fixtures Model Signals Forms Template URL Resolver View Template Loader Middleware Middleware Request Response
    42. 42. Architecture RDBMS Storage ORM Fixtures Model Signals Forms Template URL Resolver View Template Loader Middleware Middleware Request Response
    43. 43. Deep Dive: Templates <html><body> {% if posts %} {% for post in posts %} {{ post.author }}: {{ post.title }} {% endfor %} {% endif %}
    44. 44. Deep Dive: Templates <html><body> {% if posts %} {% for post in posts %} {{ post.author }}: {{ post.title }} {% endfor %} {% endif %} <form method=”post”> <table> {{ form }} </table> </form>
    45. 45. Deep Dive: Templates <html><body> {% if posts %} {% for post in posts %} {{ post.author }}: {{ post.title }} {% endfor %} {% endif %} <form method=”post”> <ul> {{ form.as_ul }} </ul> </form>
    46. 46. Architecture RDBMS Storage ORM Fixtures Model Signals Forms Template URL Resolver View Template Loader Middleware Middleware Request Response
    47. 47. Getting Started • Pure Python - no compiled code • No dependencies (with the exception of the database adapter of your choice • Three-step install • D/L and extract tar • Run setup.py • Add django-admin.py to path (optional)
    48. 48. Initialize Your Project $ django-admin.py startproject mysite $ cd mysite $ python manage.py startapp myapp $ edit settings.py and set DB Info $ python manage.py runserver http://localhost:8000
    49. 49. Killer Features • Legacy DB • Generic Views • Test Framework • Template Inheritance • Multi-DB • Tempalte Filters • Geodjango • Humanize • Aggregation • Runs on Jython / IronPython • JSON Serializer • Stable API Promise • Google AppEngine! • Fantastic Docs
    50. 50. Roll Your Own • Model Managers: Custom database API for views • Custom Template Tags: Easier to implement functionality without mixing logic/presentation
    51. 51. Roll Your Own • Model Managers: Custom database API for views • Custom Template Tags: Easier to implement functionality without mixing logic/presentation • ORM Layer • Model Fields • Template Engine • Form Fields • Template Loader • URL Resolver
    52. 52. Re-usable Apps and Pinax • Following best practices when creating your app allows others to plug in and use it • Search Google Code for *django* projects returns 1,987 results - many are apps • James Tauber created Django Hotclub to establish standards for app development and integration • Hotclub later become Pinax
    53. 53. Framework Death-match Photo by Bruce Turner
    54. 54. Death-match: RoR • URL Handling • RoR: RESTful with HTTP verbs • Django: RegEx-based URL patterns • JavaScript / AJAX • RoR: XHR helpers with RJS, prototype, scriptaculous • Django: JS framework agnostic / no helpers besides serialization
    55. 55. Death-match: RoR • Unicode • Ruby traditionally has had issues - string is byte sequence • Python is fully Unicode since v1.6 (circa 2000) • i18n • RoR: Translations are copied - no fallback? • Django: Translations use GNU gettext-style localization - falls back to default language
    56. 56. Death-match: RoR • Plugins • RoR: Rich plugin API and structure • Django: Re-usable applications • Automation / Build • RoR: rake is a rich scripting language for automated tasks • Django: manage.py can do some basic tricks - CLI
    57. 57. Death-match: RoR • Jobs: Rails jobs out-number Django jobs 6:1 • Hype: Rails has done a fantastic job with marketing
    58. 58. Death-match: RoR • Jobs: Rails jobs out-number Django jobs 6:1 • Hype: Rails has done a fantastic job with marketing
    59. 59. Recap
    60. 60. Recap • Django is easy
    61. 61. Recap • Django is easy • Django is fun
    62. 62. Recap • Django is easy • Django is fun • Django scales
    63. 63. Recap • Django is easy • Django is fun • Django scales • Django is maintainable
    64. 64. Recap • Django is easy • Django is fun • Django scales • Django is maintainable • Django saves small kittens
    65. 65. Recap • Django is easy • Django is fun • Django scales • Django is maintainable • Django saves small kittens • It rocks - USE IT!
    66. 66. Resources • http://djangoproject.com • Check out the tutorial! • http://docs.djangoproject.com • http://djangodose.com • http://www.b-list.org/ • http://pinaxproject.com • http://code.google.com/hosting/search? q=label%3aDjango
    67. 67. Thanks! rob@robyates.org Twitter: @Rob_Yates http://robyates.org

    ×