SlideShare a Scribd company logo
Topic: Django Introduction Authors: timchen119.nospam.at.gmail.com ( 使徒提姆 ) Location: Taiwan COSCUP 2008 Date: 2008/08/23 Blog: http://timchen119.blogspot.com This document has licensed as CC-SA 2.0
Topic Django Overview Introduce Django Django Status Install Guide Quick Tutorial form processing/generic view/session management/cache system/middleware Django standard library Conclude
 
Django's MVC term Model -> Model View -> template Controller -> View
 
Web 「Framework」? A web application framework is a set of software tools and libraries to make it easier to create web applications. They typically provide functionality such as database access, templating and session management. -- wikipedia
Why? CGI Scripting Language (perl,ASP,PHP) Web Framework: Code reuse Separate environment Template MVC pattern
Why Django (and Python?)
Django or...? (Framework comparisons from Django Blog) http://tinyurl.com/2f847c Person 1: "What do you do for a living?" Person 2: "I work with computers." Person 1: "So do I! What do you do with computers?" Person 2: "I'm a Web developer." Person 1: "So am I! Design, client-side programming or server-side programming?" Person 2: "Server-side programming."
Django or...? (cont.) Person 1: "Same here! Do you use dynamically typed languages or statically typed languages?" Person 2: "Dynamically typed languages." Person 1: "So do I! Do you use a Web framework, or do you roll things on your own?" Person 2: "I use a Web framework."
Django or...? (cont.) Person 1: "So do I! Django or Rails?" Person 2: "Django." Person 1: "Die, heretic scum!" (去死吧異教徒雜碎!)
Warning... One thing is clear, though: everyone's getting stuff done, regardless of their language choice. The whole debate isn't actually about productivity at all, even though most people still think it is.  It's about whether you can stand to live in a house where the bed isn't made.  -- Steve Yegge
Django's Status January 11, 2006 -- 0.91 July 29, 2006 -- 0.95 ('magic-removal') March 23, 2007 -- 0.96 (cleanup and stabilization 0.95) August 14, 2008 -- 1.0 beta 1. September 2, 2009 -- 1.0 release planned.
New in Django 1.0 newforms-admin Improved Unicode handling Automatic escaping of template variables An improved Django ORM django.contrib.gis -- (GeoDjango, merged into trunk on August 5th, 2008) Pluggable file storage Jython 2.5 support
Install guide Python Django Database System + Database Python Bindings (mysql/postgres/sqlite/oracle) Web Server (apache/lighttpd) mod_python or fastcgi (WSGI actually) Javascript Library (jquery/yui/dojo) Windows --  http://www.instantdjango.com/
Stuff you need to start. Learn Django management tools django-admin.py manage.py Edit Settings.py (setup you env) Basic Models Concept Basic Template Request and response object URLconf (urls.py) Sessions
Create Empty Project django-admin.py startproject TestProj TestProj/ __init__.py manage.py settings.py urls.py
Start to create an application python manage.py startapp TestAP TestProj/TestAP/ __init__.py views.py models.py
How to Create your web application Setup/Create Database  Edit settings.py python manage.py syncdb build your ORM model Edit models.py class Msg(models.Model): name = models.CharField(maxlength=64) date = models.DateTimeField('postdate')
How to Create your web application (cont.) Write HTML Template <html><head><title>test</title></head><body> (insert template code here)</body></html> {%if msgs_list %} {% for msg in msgs_list %} {{ msg.name }} at {{msg.date}} </p> <p> {{msg.msgtxt}} </p> {% endfor %} {%else %} <p>No Announce are available  {%endif %}
How to Create your web application (cont.) View (controller) Edit views.py def announce_index(request):  latest_msg = Msg.objects.all().order_by('date')[:5]  return render_to_response('announce.html',  {'msgs_list': latest_msg})
How to Create your web application (cont.) URLs management Edit urls.py urlpatterns = patterns( 'TestProj .TestAP.views ', (r ' ^$ ' ,  ' announce_index ' ) , ('abc', 'announce_index'), (r'^admin/',include('django.contrib.admin.urls')), )
Run,See,and Believe. python manage.py runserver   A builtin web server for development. A full database admin console on  http://127.0.0.1:8000/admin No more php(xxx)admin! python manage.py rundbshell python manage.py runshell
Web Form Processing Roll your own oldforms Newforms Accessibility Usability Validation Detailed error messages Create forms from models: form_for_model()
Generic View Provide common views of an object without actually needing to write any Python code It's nothing about View in MVC, it’s about reuse controller logic. It’s not MAGIC! Django provide most common patterns and you can extend it.
Reuse your logic &quot;Simple&quot; generic views Date-based generic views List/detail generic views Pagination Create/update/delete generic views You could use it in urls.py or views.py Simple logic => just use it in urls.py!
stateful HTTP Cookies Django session framework User and Auth framework django.contrib.auth Permissions Groups Messages Profiles
Cache system Different cache backend: Database Filesystem Memory Memcached Different cache Scope: Per Site Per View Low Level Cache API to cache part of results (and any python object which can be safely pickled)
Middleware MIDDLEWARE_CLASSES Implies... Classes which is a Middleware Methods middleware defines: __init__ process_request process_view process_response process_exception Django have lots of builtin Middlewares
Django Standard Library django.contrib admin auth comments contenttypes csrf databrowse flatpages formtools humanize
Django Standard Library markup redirects sessions sitemaps sites syndication
Lots of Stuff in django You can Use/Learn/extends User Registration Custom Template Tags/Filters Add Voting and Comments Creating your own Admin Interface Ajax via simplejson Add Complex Model relations RSS / Sitemap Framework Test via Unit test Write Middleware
Lots of Stuff You also need to learn Django won ’ t magically turn you from newbie to Web pros. It just let your life easier. Learn HTML / XHTML. (learn how to struct) Learn CSS / Javascript and get your firebug. (CSS2.1/Prototype/Dojo/YUI/Mochkit/jQuery). Learn Browser.(IE7, IE6, IE5.5, firefox [gecko], opera, Safari) Learn SQL (learn how to maintain/transfer data) Learn Apache / lighttpd / flup / mod_python / Http (learn how to scale) Learn You ’ re not genius. Learn from other (genius) people. Don ’ t reinvent a WORSE wheel.
Thanks!

More Related Content

ODP
Introduction to Django
PPTX
Django Framework Overview forNon-Python Developers
KEY
Web application development with Django framework
PDF
Introduction to django
PDF
Building Pluggable Web Applications using Django
ODP
Django for Beginners
PDF
Building a Dynamic Website Using Django
Introduction to Django
Django Framework Overview forNon-Python Developers
Web application development with Django framework
Introduction to django
Building Pluggable Web Applications using Django
Django for Beginners
Building a Dynamic Website Using Django

What's hot (20)

PPTX
PDF
Web develop in flask
PDF
Django best practices for logging and signals
PPT
Apache Ant
PDF
Maven 3.0 at Øredev
PDF
A Basic Django Introduction
PDF
Mastering Maven 2.0 In 1 Hour V1.3
PDF
Python RESTful webservices with Python: Flask and Django solutions
PPT
Apache Ant
PPTX
The Django Web Application Framework 2
PDF
Django a whirlwind tour
PPTX
Django Interview Questions and Answers
PPTX
Apache Ant
PPTX
Apache ant
PPTX
Apache ant
PPT
Ant - Another Neat Tool
PDF
Best Practices for Front-End Django Developers
PPTX
Django Girls Tutorial
PDF
Automation - fabric, django and more
PDF
Introduction to Apache Ant
Web develop in flask
Django best practices for logging and signals
Apache Ant
Maven 3.0 at Øredev
A Basic Django Introduction
Mastering Maven 2.0 In 1 Hour V1.3
Python RESTful webservices with Python: Flask and Django solutions
Apache Ant
The Django Web Application Framework 2
Django a whirlwind tour
Django Interview Questions and Answers
Apache Ant
Apache ant
Apache ant
Ant - Another Neat Tool
Best Practices for Front-End Django Developers
Django Girls Tutorial
Automation - fabric, django and more
Introduction to Apache Ant
Ad

Viewers also liked (10)

ODP
Django shop
PDF
Django workshop : let's make a blog
PDF
Django in Windows
PPT
Multi Tenancy With Python and Django
PPTX
Big o notation
PPT
Django CMS & Integrating it with django shop
PDF
12 tips on Django Best Practices
PDF
The Best (and Worst) of Django
PDF
The Django Web Application Framework
PDF
Web Development with Python and Django
Django shop
Django workshop : let's make a blog
Django in Windows
Multi Tenancy With Python and Django
Big o notation
Django CMS & Integrating it with django shop
12 tips on Django Best Practices
The Best (and Worst) of Django
The Django Web Application Framework
Web Development with Python and Django
Ad

Similar to dJango (20)

ODP
Introduce Django
DOCX
Akash rajguru project report sem v
PDF
Introduction to Django
PPTX
Tango with django
PDF
django
PDF
Why Django
PDF
Python & Django TTT
PPTX
Django course
PDF
Introduction to Python and Django
PDF
Django Documentation
PDF
Django in Action (MEAP V01) Christopher Trudeau
PPTX
Django Architecture Introduction
PPTX
Django Framework Interview Question and Answer partOne.pptx
PPTX
Django framework
PDF
PPTX
Introduction and features to Django.pptx
PPTX
Django Framework Interview Guide - Part 1
PDF
Django in Action (MEAP V01) Christopher Trudeau
KEY
Jumpstart Django
PDF
Intro to Web Development Using Python and Django
Introduce Django
Akash rajguru project report sem v
Introduction to Django
Tango with django
django
Why Django
Python & Django TTT
Django course
Introduction to Python and Django
Django Documentation
Django in Action (MEAP V01) Christopher Trudeau
Django Architecture Introduction
Django Framework Interview Question and Answer partOne.pptx
Django framework
Introduction and features to Django.pptx
Django Framework Interview Guide - Part 1
Django in Action (MEAP V01) Christopher Trudeau
Jumpstart Django
Intro to Web Development Using Python and Django

More from Bob Chao (20)

PDF
簡報規劃與設計
PDF
開放社群,啊是多開放?
PDF
數位教材公眾授權資源蒐集與創用 CC 資源網站
PDF
Vidyo: How to Record and Broadcast your meeting
PDF
Mozilla Community
PDF
開源人生指南 - 如何不慎豐富人脈與經驗
PDF
開放文化基金會可以幫你什麼?
PDF
Firefox OS Add-on in 10 minutes
PDF
Build your own COSCUP
PDF
COSCUP: What, Why, and How
PDF
OCF 募款餐會: 開放文化影展
PDF
8 個重回 Firefox 的理由 8 reasons back to Firefox
PDF
Webmaker Workshop: Popcorn maker in 60mins
PDF
Webmaker Workshop: Appmaker in 60mins
PDF
Google Analytics 網站分析: 學習心得分享
PDF
Mozilla Webmaker: Brief Intro.
PDF
OpenSource 新手上路
PDF
給 FLOSS 社群網站管理志工的網站分析入門 - 以 Google Analytics 為例
PDF
網站分析 我小的時候以為自己會
PDF
Gamification 遊戲化是在 Play 蝦米 Game
簡報規劃與設計
開放社群,啊是多開放?
數位教材公眾授權資源蒐集與創用 CC 資源網站
Vidyo: How to Record and Broadcast your meeting
Mozilla Community
開源人生指南 - 如何不慎豐富人脈與經驗
開放文化基金會可以幫你什麼?
Firefox OS Add-on in 10 minutes
Build your own COSCUP
COSCUP: What, Why, and How
OCF 募款餐會: 開放文化影展
8 個重回 Firefox 的理由 8 reasons back to Firefox
Webmaker Workshop: Popcorn maker in 60mins
Webmaker Workshop: Appmaker in 60mins
Google Analytics 網站分析: 學習心得分享
Mozilla Webmaker: Brief Intro.
OpenSource 新手上路
給 FLOSS 社群網站管理志工的網站分析入門 - 以 Google Analytics 為例
網站分析 我小的時候以為自己會
Gamification 遊戲化是在 Play 蝦米 Game

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Per capita expenditure prediction using model stacking based on satellite ima...
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto

dJango

  • 1. Topic: Django Introduction Authors: timchen119.nospam.at.gmail.com ( 使徒提姆 ) Location: Taiwan COSCUP 2008 Date: 2008/08/23 Blog: http://timchen119.blogspot.com This document has licensed as CC-SA 2.0
  • 2. Topic Django Overview Introduce Django Django Status Install Guide Quick Tutorial form processing/generic view/session management/cache system/middleware Django standard library Conclude
  • 3.  
  • 4. Django's MVC term Model -> Model View -> template Controller -> View
  • 5.  
  • 6. Web 「Framework」? A web application framework is a set of software tools and libraries to make it easier to create web applications. They typically provide functionality such as database access, templating and session management. -- wikipedia
  • 7. Why? CGI Scripting Language (perl,ASP,PHP) Web Framework: Code reuse Separate environment Template MVC pattern
  • 8. Why Django (and Python?)
  • 9. Django or...? (Framework comparisons from Django Blog) http://tinyurl.com/2f847c Person 1: &quot;What do you do for a living?&quot; Person 2: &quot;I work with computers.&quot; Person 1: &quot;So do I! What do you do with computers?&quot; Person 2: &quot;I'm a Web developer.&quot; Person 1: &quot;So am I! Design, client-side programming or server-side programming?&quot; Person 2: &quot;Server-side programming.&quot;
  • 10. Django or...? (cont.) Person 1: &quot;Same here! Do you use dynamically typed languages or statically typed languages?&quot; Person 2: &quot;Dynamically typed languages.&quot; Person 1: &quot;So do I! Do you use a Web framework, or do you roll things on your own?&quot; Person 2: &quot;I use a Web framework.&quot;
  • 11. Django or...? (cont.) Person 1: &quot;So do I! Django or Rails?&quot; Person 2: &quot;Django.&quot; Person 1: &quot;Die, heretic scum!&quot; (去死吧異教徒雜碎!)
  • 12. Warning... One thing is clear, though: everyone's getting stuff done, regardless of their language choice. The whole debate isn't actually about productivity at all, even though most people still think it is. It's about whether you can stand to live in a house where the bed isn't made. -- Steve Yegge
  • 13. Django's Status January 11, 2006 -- 0.91 July 29, 2006 -- 0.95 ('magic-removal') March 23, 2007 -- 0.96 (cleanup and stabilization 0.95) August 14, 2008 -- 1.0 beta 1. September 2, 2009 -- 1.0 release planned.
  • 14. New in Django 1.0 newforms-admin Improved Unicode handling Automatic escaping of template variables An improved Django ORM django.contrib.gis -- (GeoDjango, merged into trunk on August 5th, 2008) Pluggable file storage Jython 2.5 support
  • 15. Install guide Python Django Database System + Database Python Bindings (mysql/postgres/sqlite/oracle) Web Server (apache/lighttpd) mod_python or fastcgi (WSGI actually) Javascript Library (jquery/yui/dojo) Windows -- http://www.instantdjango.com/
  • 16. Stuff you need to start. Learn Django management tools django-admin.py manage.py Edit Settings.py (setup you env) Basic Models Concept Basic Template Request and response object URLconf (urls.py) Sessions
  • 17. Create Empty Project django-admin.py startproject TestProj TestProj/ __init__.py manage.py settings.py urls.py
  • 18. Start to create an application python manage.py startapp TestAP TestProj/TestAP/ __init__.py views.py models.py
  • 19. How to Create your web application Setup/Create Database Edit settings.py python manage.py syncdb build your ORM model Edit models.py class Msg(models.Model): name = models.CharField(maxlength=64) date = models.DateTimeField('postdate')
  • 20. How to Create your web application (cont.) Write HTML Template <html><head><title>test</title></head><body> (insert template code here)</body></html> {%if msgs_list %} {% for msg in msgs_list %} {{ msg.name }} at {{msg.date}} </p> <p> {{msg.msgtxt}} </p> {% endfor %} {%else %} <p>No Announce are available {%endif %}
  • 21. How to Create your web application (cont.) View (controller) Edit views.py def announce_index(request): latest_msg = Msg.objects.all().order_by('date')[:5] return render_to_response('announce.html', {'msgs_list': latest_msg})
  • 22. How to Create your web application (cont.) URLs management Edit urls.py urlpatterns = patterns( 'TestProj .TestAP.views ', (r ' ^$ ' , ' announce_index ' ) , ('abc', 'announce_index'), (r'^admin/',include('django.contrib.admin.urls')), )
  • 23. Run,See,and Believe. python manage.py runserver A builtin web server for development. A full database admin console on http://127.0.0.1:8000/admin No more php(xxx)admin! python manage.py rundbshell python manage.py runshell
  • 24. Web Form Processing Roll your own oldforms Newforms Accessibility Usability Validation Detailed error messages Create forms from models: form_for_model()
  • 25. Generic View Provide common views of an object without actually needing to write any Python code It's nothing about View in MVC, it’s about reuse controller logic. It’s not MAGIC! Django provide most common patterns and you can extend it.
  • 26. Reuse your logic &quot;Simple&quot; generic views Date-based generic views List/detail generic views Pagination Create/update/delete generic views You could use it in urls.py or views.py Simple logic => just use it in urls.py!
  • 27. stateful HTTP Cookies Django session framework User and Auth framework django.contrib.auth Permissions Groups Messages Profiles
  • 28. Cache system Different cache backend: Database Filesystem Memory Memcached Different cache Scope: Per Site Per View Low Level Cache API to cache part of results (and any python object which can be safely pickled)
  • 29. Middleware MIDDLEWARE_CLASSES Implies... Classes which is a Middleware Methods middleware defines: __init__ process_request process_view process_response process_exception Django have lots of builtin Middlewares
  • 30. Django Standard Library django.contrib admin auth comments contenttypes csrf databrowse flatpages formtools humanize
  • 31. Django Standard Library markup redirects sessions sitemaps sites syndication
  • 32. Lots of Stuff in django You can Use/Learn/extends User Registration Custom Template Tags/Filters Add Voting and Comments Creating your own Admin Interface Ajax via simplejson Add Complex Model relations RSS / Sitemap Framework Test via Unit test Write Middleware
  • 33. Lots of Stuff You also need to learn Django won ’ t magically turn you from newbie to Web pros. It just let your life easier. Learn HTML / XHTML. (learn how to struct) Learn CSS / Javascript and get your firebug. (CSS2.1/Prototype/Dojo/YUI/Mochkit/jQuery). Learn Browser.(IE7, IE6, IE5.5, firefox [gecko], opera, Safari) Learn SQL (learn how to maintain/transfer data) Learn Apache / lighttpd / flup / mod_python / Http (learn how to scale) Learn You ’ re not genius. Learn from other (genius) people. Don ’ t reinvent a WORSE wheel.