Useful Django 1.4

  • Published on
    06-May-2015

  • View
    690

  • Download
    2

Embed Size (px)

DESCRIPTION

About Django, Project template, django-skel.

Transcript

<ul><li>1.Useful Django1.4Django &amp; Pyramid Con 2012@hirokiky12918</li></ul> <p>2. Useful Django1.4 About me (2m) About Django (19m) Useful things of Django &gt; 1.0 (19m)Speaker: @hirokiky12918 3. Useful Django1.4 About me About Django Useful things of Django &gt; 1.0 Speaker: @hirokiky12918 4. About me @hirokiky (Hiroki KIYOHARA) Weekend Programmer Admin of djangoproject.jp Speaker: @hirokiky12918 5. djangoproject.jphttp://djangoproject.jp/ https://github.com/django-ja/djangoproject.jp/ Speaker: @hirokiky12918 6. Useful Django1.4 About me About Django Useful things of Django &gt; 1.0 Speaker: @hirokiky12918 7. Django is a Open Source Web framework written by Python.Speaker: @hirokiky12918 8. DjangoSites Disqus Instagram Mozilla bitbucketSpeaker: @hirokiky12918 9. WebServerrequestTemplateURL Dispatcherresponse ViewModel DataBaseSpeaker: @hirokiky12918 10. Philosophies Loose coupling Less code Quick development Don t repeat yourself (DRY) Explicit is better than implict Consistencyhttps://docs.djangoproject.com/en/1.4/misc/design-philosophies/Speaker: @hirokiky12918 11. Killer features Automatically-generated admin site Form library Generic views Speaker: @hirokiky12918 12. Admin site Automatically-generated Easy to customize Speaker: @hirokiky12918 13. Demo: Admin (15m) startproject, create models, run admin site(10m) Introduction of django-blog-zinnia (5m) Speaker: @hirokiky12918 14. Read Docsand some codes If you want to learn more Speaker: @hirokiky12918 15. Useful Django1.4 About me About Django Useful things of Django &gt; 1.0 Speaker: @hirokiky12918 16. Django &gt; 1.0 project template Class Based View Speaker: @hirokiky12918 17. project template Django&gt;=1.4 template of projecthttps://docs.djangoproject.com/en/dev/releases/1.4/#custom-project-and-app-templatesSpeaker: @hirokiky12918 18. Project template provide easy deploy to a specic environment archiving some best practicesSpeaker: @hirokiky12918 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: @hirokiky12918 20. Solving all of these by templatingSpeaker: @hirokiky12918 21. How to useproject templatedjango-admin.py startproject --template=/path/to/template myproject --template=/path/to/template also URLSpeaker: @hirokiky12918 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.pySpeaker: @hirokiky12918 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.pySpeaker: @hirokiky12918 24. Also .py les 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 les specied by optionSpeaker: @hirokiky12918 25. In essenceYou can use own project template,instead of django/conf/project_template Speaker: @hirokiky12918 26. Example: django-skel heroku + S3 platform Filled with best practices that rdegges havelearned for four years. https://github.com/rdegges/django-skelSpeaker: @hirokiky12918 27. WorkowSpeaker: @hirokiky12918 28. Before developing startproject --template ... git init pip install -r reqs/dev.txt sync, migrate, runserver Speaker: @hirokiky12918 29. Hack some apps (not projects) Speaker: @hirokiky12918 30. Before deploying fab bootstrap heroku config:add ... heroku scale ... collectstatic &amp;&amp; compressSpeaker: @hirokiky12918 31. Good joooooo( )oooooob!!!! Speaker: @hirokiky12918 32. Let s learn best practicesfrom django-skel Judging environments apps directorySpeaker: @hirokiky12918 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 settingslayout common.py dev.py __init__.py prod.py templates 404.html 500.html urls.py wsgi.py Speaker: @hirokiky12918 34. Judging environments Judging environments automaticaly. Don t do hardcoding (settings.DEBUG = TrueSpeaker: @hirokiky12918 35. On django-skel settings __init__.py common.py dev.py prod.py Only development setting will put in dev.py settings for production =&gt; prod.py Common settings =&gt; common.py heroku config:add DJANGO_SETTINGS_MODULE={{ project_name }}.settings.prod Speaker: @hirokiky12918 36. apps directory Directory for applications For avoiding import collisionSpeaker: @hirokiky12918 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.pySpeaker: @hirokiky12918 38. . # here, path|-- aggregator| |-- __init__.py| |-- blog.pyIf 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.pySpeaker: @hirokiky12918 39. . # here, path|-- apps| |-- __init__.py| |-- aggregator| | |-- __init__.pyThen 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: @hirokiky12918 40. Project template provide easy deploy to a specic environment archiving some best practicesSpeaker: @hirokiky12918 41. Luke of Django Deploy project avoiding HELL Learn best practices through readinggood project templatesSpeaker: @hirokiky12918 42. Yoda of Django Without remembering best practicesand adapting to new project to these Create Django s default standards inthe form of project template Speaker: @hirokiky12918 43. Killer Feature of Django1.4is not only {% elif %} Speaker: @hirokiky12918 44. Announce I held DjangoSprint 2012 September 17 It don t force you what to do. http://2012.pycon.jp/en/program/sprints.htmlSpeaker: @hirokiky12918 45. Thank youSpeaker: @hirokiky12918 46. Any questions?Speaker: @hirokiky12918 47. References djangoproject.jp djangoproject.com django-blog-zinnia django-skel Speaker: @hirokiky12918 48. django-docs-ja We are translating Django1.4 documents to Japanesehttps://github.com/django-docs-ja/django-docs-ja Speaker: @hirokiky12918 </p>