Successfully reported this slideshow.
Your SlideShare is downloading. ×

Useful Django 1.4

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
使えるDjango1.4
使えるDjango1.4
Loading in …3
×

Check these out next

1 of 48 Ad

More Related Content

Slideshows for you (20)

Advertisement

Similar to Useful Django 1.4 (20)

More from hirokiky (16)

Advertisement

Recently uploaded (20)

Useful Django 1.4

  1. 1. Useful Django1.4 Django & Pyramid Con 2012 @hirokiky 12年9月18日火曜日
  2. 2. Useful Django1.4 • About me (2m) • About Django (19m) • Useful things of Django > 1.0 (19m) Speaker: @hirokiky 12年9月18日火曜日
  3. 3. Useful Django1.4 • About me • About Django • Useful things of Django > 1.0 Speaker: @hirokiky 12年9月18日火曜日
  4. 4. About me • @hirokiky (Hiroki KIYOHARA) • Weekend Programmer • Admin of djangoproject.jp Speaker: @hirokiky 12年9月18日火曜日
  5. 5. djangoproject.jp http://djangoproject.jp/ https://github.com/django-ja/djangoproject.jp/ Speaker: @hirokiky 12年9月18日火曜日
  6. 6. Useful Django1.4 • About me • About Django • Useful things of Django > 1.0 Speaker: @hirokiky 12年9月18日火曜日
  7. 7. Django is a Open Source Web framework written by Python. Speaker: @hirokiky 12年9月18日火曜日
  8. 8. DjangoSites • Disqus • Instagram • Mozilla • bitbucket Speaker: @hirokiky 12年9月18日火曜日
  9. 9. WebServer request Template URL Dispatcher response View Model DataBase Speaker: @hirokiky 12年9月18日火曜日
  10. 10. Philosophies • Loose coupling • Less code • Quick development • Don t repeat yourself (DRY) • Explicit is better than implict • Consistency https://docs.djangoproject.com/en/1.4/misc/design-philosophies/ Speaker: @hirokiky 12年9月18日火曜日
  11. 11. Killer features • Automatically-generated admin site • Form library • Generic views Speaker: @hirokiky 12年9月18日火曜日
  12. 12. Admin site • Automatically-generated • Easy to customize Speaker: @hirokiky 12年9月18日火曜日
  13. 13. Demo: Admin (15m) • startproject, create models, run admin site(10m) • Introduction of django-blog-zinnia (5m) Speaker: @hirokiky 12年9月18日火曜日
  14. 14. Read Docs and some codes If you want to learn more Speaker: @hirokiky 12年9月18日火曜日
  15. 15. Useful Django1.4 • About me • About Django • Useful things of Django > 1.0 Speaker: @hirokiky 12年9月18日火曜日
  16. 16. Django > 1.0 • project template • <del>Class Based View</del> <!-- Because of time constraints --> Speaker: @hirokiky 12年9月18日火曜日
  17. 17. project template • Django>=1.4 • template of project https://docs.djangoproject.com/en/dev/releases/1.4/#custom-project-and-app-templates Speaker: @hirokiky 12年9月18日火曜日
  18. 18. Project template provide • easy deploy to a specific environment • archiving some best practices Speaker: @hirokiky 12年9月18日火曜日
  19. 19. Boring tasks after startproject • Judging environments (DEBUG, True or False. • A application should put in project/apps. (not default, but good know-how • Writing dependences. • Dealing informations we want to write in settings (SECRET_KEY, PASSWORD Speaker: @hirokiky 12年9月18日火曜日
  20. 20. Solving all of these by templating Speaker: @hirokiky 12年9月18日火曜日
  21. 21. How to use project template django-admin.py startproject --template=/path/to/template myproject --template=/path/to/template also URL Speaker: @hirokiky 12年9月18日火曜日
  22. 22. template ├──  fabfile.py ├──  gunicorn.py.ini ├──  manage.py ├──  Procfile ├──  reqs │      ├──  common.txt template is like this │      ├──  dev.txt │      └──  prod.txt ├──  requirements.txt (A directory) ├──  project_name │      ├──  apps │      │      └──  __init__.py │      ├──  __init__.py │      ├──  libs │      │      └──  __init__.py │      ├──  settings │      │      ├──  common.py │      │      ├──  dev.py │      │      ├──  __init__.py │      │      └──  prod.py │      ├──  templates │      │      ├──  404.html │      │      └──  500.html │      └──  urls.py └──  wsgi.py Speaker: @hirokiky 12年9月18日火曜日
  23. 23. template ├──  fabfile.py ├──  gunicorn.py.ini ├──  manage.py ├──  Procfile ├──  reqs │      ├──  common.txt template is like this │      ├──  dev.txt │      └──  prod.txt ├──  requirements.txt ├──  project_name │      ├──  apps │      │      └──  __init__.py This name will be │      ├──  __init__.py │      ├──  libs │      │      └──  __init__.py replaced with │      ├──  settings │      │      ├──  common.py project s name │      │      ├──  dev.py │      │      ├──  __init__.py │      │      └──  prod.py │      ├──  templates │      │      ├──  404.html │      │      └──  500.html │      └──  urls.py └──  wsgi.py Speaker: @hirokiky 12年9月18日火曜日
  24. 24. Also .py files if  __name__  ==  "__main__":        os.environ.setdefault("DJANGO_SETTINGS_MODULE",  "{{  project_name  }}.settings.dev")        from  django.core.management  import  execute_from_command_line        execute_from_command_line(sys.argv) • project_name • project_directory • secret_key • Also another files specified by option Speaker: @hirokiky 12年9月18日火曜日
  25. 25. In essence You can use own project template, instead of django/conf/project_template Speaker: @hirokiky 12年9月18日火曜日
  26. 26. Example: django-skel • heroku + S3 platform • Filled with best practices that rdegges have learned for four years. https://github.com/rdegges/django-skel Speaker: @hirokiky 12年9月18日火曜日
  27. 27. Workflow Speaker: @hirokiky 12年9月18日火曜日
  28. 28. Before developing • startproject --template ... • git init • pip install -r reqs/dev.txt • sync, migrate, runserver Speaker: @hirokiky 12年9月18日火曜日
  29. 29. Hack some apps (not projects) Speaker: @hirokiky 12年9月18日火曜日
  30. 30. Before deploying • fab  bootstrap • heroku  config:add  ... • heroku  scale  ... • collectstatic  &&  compress Speaker: @hirokiky 12年9月18日火曜日
  31. 31. Good joooooo( ́ `)oooooob!!!! Speaker: @hirokiky 12年9月18日火曜日
  32. 32. Let s learn best practices from django-skel • Judging environments • apps directory Speaker: @hirokiky 12年9月18日火曜日
  33. 33. django-­‐skel ├──  fabfile.py ├──  gunicorn.py.ini ├──  manage.py ├──  Procfile ├──  reqs │      ├──  common.txt │      ├──  dev.txt │      └──  prod.txt ├──  requirements.txt Note: ├──  project_name │      ├──  apps │      │      └──  __init__.py │      ├──  __init__.py django-skel s │      ├──  libs │      │      └──  __init__.py │      ├──  settings layout │      │      ├──  common.py │      │      ├──  dev.py │      │      ├──  __init__.py │      │      └──  prod.py │      ├──  templates │      │      ├──  404.html │      │      └──  500.html │      └──  urls.py └──  wsgi.py Speaker: @hirokiky 12年9月18日火曜日
  34. 34. Judging environments • Judging environments automaticaly. • Don t do hardcoding (settings.DEBUG = True Speaker: @hirokiky 12年9月18日火曜日
  35. 35. On django-skel ├──  settings │      │      ├──  __init__.py │      │      ├──  common.py │      │      ├──  dev.py │      │      └──  prod.py • Only  development  setting  will  put  in  dev.py • settings  for  production  =>  prod.py • Common  settings  =>  common.py • heroku  config:add   DJANGO_SETTINGS_MODULE={{  project_name  }}.settings.prod Speaker: @hirokiky 12年9月18日火曜日
  36. 36. apps directory • Directory for applications • For avoiding import collision Speaker: @hirokiky 12年9月18日火曜日
  37. 37. django-­‐skel ├──  fabfile.py ├──  gunicorn.py.ini ├──  manage.py ├──  Procfile ├──  reqs │      ├──  common.txt │      ├──  dev.txt │      └──  prod.txt ├──  requirements.txt ├──  project_name │      ├──  apps Here │      │      └──  __init__.py │      ├──  __init__.py │      ├──  libs │      │      └──  __init__.py │      ├──  settings │      │      ├──  common.py │      │      ├──  dev.py │      │      ├──  __init__.py │      │      └──  prod.py │      ├──  templates │      │      ├──  404.html │      │      └──  500.html │      └──  urls.py └──  wsgi.py Speaker: @hirokiky 12年9月18日火曜日
  38. 38. .  #  here,  path |-­‐-­‐  aggregator |      |-­‐-­‐  __init__.py |      |-­‐-­‐  blog.py If no apps/ |      |-­‐-­‐  models.py |      |-­‐-­‐  tests.py |      `-­‐-­‐  views.py |-­‐-­‐  blog • Ex: In aggregator.views |      |-­‐-­‐  __init__.py |      |-­‐-­‐  models.py |      |-­‐-­‐  tests.py |      `-­‐-­‐  views.py |-­‐-­‐  manage.py `-­‐-­‐  myprj • from blog.models import Entry • ImportError        |-­‐-­‐  __init__.py        |-­‐-­‐  settings.py        |-­‐-­‐  urls.py        `-­‐-­‐  wsgi.py Speaker: @hirokiky 12年9月18日火曜日
  39. 39. .  #  here,  path |-­‐-­‐  apps |      |-­‐-­‐  __init__.py |      |-­‐-­‐  aggregator |      |      |-­‐-­‐  __init__.py Then apps/ |      |      |-­‐-­‐  blog.py |      |      |-­‐-­‐  models.py |      |      |-­‐-­‐  tests.py |      |      `-­‐-­‐  views.py |      `-­‐-­‐  blog |              |-­‐-­‐  __init__.py |              |-­‐-­‐  models.py |              |-­‐-­‐  tests.py |              `-­‐-­‐  views.py |-­‐-­‐  manage.py • from apps.blog.model import Entry `-­‐-­‐  myprj        |-­‐-­‐  __init__.py        |-­‐-­‐  settings.py        |-­‐-­‐  urls.py        `-­‐-­‐  wsgi.py Speaker: @hirokiky 12年9月18日火曜日
  40. 40. Project template provide • easy deploy to a specific environment • archiving some best practices Speaker: @hirokiky 12年9月18日火曜日
  41. 41. Luke of Django • Deploy project avoiding HELL • Learn best practices through reading good project templates Speaker: @hirokiky 12年9月18日火曜日
  42. 42. Yoda of Django • Without remembering best practices and adapting to new project to these • Create Django s default standards in the form of project template Speaker: @hirokiky 12年9月18日火曜日
  43. 43. Killer Feature of Django1.4 is not only {% elif %} Speaker: @hirokiky 12年9月18日火曜日
  44. 44. Announce • I held DjangoSprint • 2012 September 17 • It don t force you what to do. • http://2012.pycon.jp/en/program/sprints.html Speaker: @hirokiky 12年9月18日火曜日
  45. 45. Thank you Speaker: @hirokiky 12年9月18日火曜日
  46. 46. Any questions? Speaker: @hirokiky 12年9月18日火曜日
  47. 47. References • djangoproject.jp • djangoproject.com • django-blog-zinnia • django-skel Speaker: @hirokiky 12年9月18日火曜日
  48. 48. django-docs-ja • We are translating Django1.4 documents to Japanese https://github.com/django-docs-ja/django-docs-ja Speaker: @hirokiky 12年9月18日火曜日

×