Intro to Pinax: Kickstarting Your Django Apps

10,363 views

Published on

Presented at Sydney Python Users Group November 2011

Published in: Technology
2 Comments
12 Likes
Statistics
Notes
No Downloads
Views
Total views
10,363
On SlideShare
0
From Embeds
0
Number of Embeds
21
Actions
Shares
0
Downloads
77
Comments
2
Likes
12
Embeds 0
No embeds

No notes for slide

Intro to Pinax: Kickstarting Your Django Apps

  1. 1. Intro to Pinax Kickstarting Your Django Apps SyPy - November 2011 Roger Barnes @mindsocketroger@mindsocket.com.au http://gplus.to/mindsocket
  2. 2. Who am I Roger Barnes BTech ICS By day: Tech Lead/Applications Developer Java :( By night: Up and coming Python ninja
  3. 3. Topics Intro to Django Intro to Pinax Alternatives Development Tips Q&A
  4. 4. What is Django ”The web framework for perfectionists with deadlines”Initially developed in an online news environment Designed for rapid development
  5. 5. Django Framework Object-relational mapper Automatic admin interface Elegant URL design Template system Caching More...  i18n, syndication, generic views, schema generation, development server, user model, scheduled jobs, test harness, ...
  6. 6. Django is... … really well documented https://docs.djangoproject.com
  7. 7. Example: More Betterer My first Django app  Goal 1: Learn some Python and Django  Goal 2: Find out what photos people liked
  8. 8. Example: More Betterer Very simple models  Item (an image)  Challenge (a showdown between 2 items) Item manager  counts challenge votes  provides ordered list
  9. 9. stLessons from 1 Django app Django alone isnt a quickstart/shortcut for  common web 2.0 functionality  OAuth, social, tagging, voting  front-end  HTML, CSS, JS This is true of many web frameworks  Either front- or back-end focussed Some best practices arent obvious  or are evolving (eg class-based views in 1.3)
  10. 10. What is Pinax System for kickstarting Django projects ”Pinax takes care of the things that many siteshave in common so you can focus on what makes your site different” Quickly go from idea to launch (and beyond)
  11. 11. What is Pinax Social friendly  Comments  Voting  Notifications  Profiles/Accounts/OAuth  ... Startup friendly  Private beta  Invite codes  Starter projects
  12. 12. When to use PinaxGreat for building and maintaining multiple sites … quickly Not as much benefit for a big enterprise app
  13. 13. Pinax - Pros and cons Pros  Has a lot to offer  Easier to start with a pinax starter and adapt Cons  Misunderstood  No recent releases (but active branches on github)  Django compatibility (Pinax 0.9a1 needed tweaks to work with Django 1.3) Overall: worth it
  14. 14. Example: Now and Then An application for aligning and overlaying historical images with modern equivalents
  15. 15. Example: Now and Then My 2nd Django app  Goal 1: Libraryhack entry - http://libraryhack.org/  Goal 2: Learn more Django & Python! Approx. 1 month development Started without Pinax  got stuck on ”common functionality” Pinax helped get past theme and account management issues
  16. 16. Example: Now and Then
  17. 17. Pinax – Primary Features Project conventions  Layout  Deployment Requirements - pip dependencies Templates - quick prototyping Core and reusable apps  Back- and front-end functionality Starter projects  Basis for a Django site, several options
  18. 18. Pinax - Layout|-- apps |-- fixtures| |-- about | `-- initial_data.json| | |-- models.py |-- locale| | |-- urls.py | |-- ...| | |-- views.py |-- manage.py| |-- my_foo_app |-- media| | |-- ... | |-- css| |-- ... | | `-- site_tabs.css| | |-- ... | |-- ...|-- deploy |-- requirements| |-- pinax.fcgi | |-- base.txt| `-- pinax.wsgi | `-- project.txt|-- dev.db |-- settings.py |-- templates | |-- about | |-- account | |-- ... |-- tests | |-- ... |-- urls.py
  19. 19. Pinax For Now and Then: Requirements (pip) PIL  Base aino-convert what pinax needs django-extensions django-memcache-status  Project django-jenkins selenium what you want to add pyvirtualdisplay MySQL-python python-memcached flickrapi south django-tagging django-voting PyYAML nltk minidetector geopy
  20. 20. Pinax Apps  account and profile management  openid, e-mail verification, password management  notifications and activity streams  private betas and waiting lists  badges  tagging  wikis, forums and blogs  task tracking  friend and follower relations
  21. 21. Pinax Starter projects  zero  basic  account  static  private_beta  cms_company  intranet  social  cms_holidayhouse  company  sample_group  code
  22. 22. Pinax Fairly well documented http://pinaxproject.com/docs/ Code on github
  23. 23. Pinax project status Still in active development (see github) A new release pending Better ecosystem management  Trying to solve the ”misunderstood” problem  http://pinaxproject.com/ecosystem/
  24. 24. Pinax isnt A silver bullet for front-end  BYO UX, design, HTML, CSS, JS skills Some solutions  Twitter bootstrap – Pinax has a new theme  Growing collection of other themes on offer  HTML5 boilerplate  Other template + less/CSS + Javascript library
  25. 25. Pinax – Idea to Launch The next big social network mytweetbooktubelyplus.com Domain name is not currently registered. Available for you now!
  26. 26. Pinax – Idea to Launch Steps  mkvirtualenv --no-site-packages mytweetbooktubelyplus  pip install Pinax  pinax-admin setup_project -b social mytweetbooktubelyplus  cd mytweetbooktubelyplus/  git init  git commit -am ”Initial commit”
  27. 27. Pinax – Idea to Launch Steps (continued)  edit settings.py  pip install PIL  Better: add to requirements or remove dependent app  python manage.py syncdb  python manage.py runserver    Profit!
  28. 28. Alternatives to Pinax Hand-pick your own bundled apps  PyPI  Djangopackages.com Other starter projects on github  Eg: django-party-pack
  29. 29. Development tips South  Schema management extension for Django  Handles updates to existing/populated DB  eg: Add/change a column in dev  Generate/deploy code to do same in test/prod  Integrates with djangos management tools
  30. 30. Development tips Environment/package management  virtualenv + pip (+ virtualenvwrapper)  For more complex deploys, look at buildout  local_settings.py (dev/test/prod)  Contains environment specific config  And passwords, add to .gitignore In settings.py try: from local_settings import * except ImportError: pass
  31. 31. Development tips - Testing Django + unittest2  Fixtures for testing models (tests.json)  Django Client to test views (request/response)def test_point_list(self): """Tests that point_list returns a valid list of lists""" fusion = Fusion() fusion.points = "1,2,3,4,5,6,7,8" self.failUnlessEqual(fusion.point_list(), [[1,2,3,4],[5,6,7,8]]) def test_fusion_edit_update(self): self._login() response = self.client.post(/fusion/edit/1/, {points: , cropthen: }) self.assertRedirects(response, /fusion/view/1/)
  32. 32. Development tips – Testing TODO UI tests  Selenium or similar to test UI, esp. javascript def test_via_selenium(self): from pyvirtualdisplay import Display from selenium import webdriver display = Display(visible=0, size=(800, 600)) display.start() browser = webdriver.Firefox() browser.get(http://myurl...) # TODO …
  33. 33. Dev tips - Continuous Integration Jenkins  Build triggered by commit (or polled)  unittest2  django-jenkins  coverage
  34. 34. Development tips - Deployment Fast all the way to production  git pull - ok for simple application  TODO: Build pipeline  TODO: Continuous Deployment Production performance  Apache + mod-wsgi – ok  Use pinax.wsgi  May need a little hacking to get paths right  TODO: try nginx + uWSGI or similar  TODO: High availability + reverse proxy
  35. 35. Development tips – Source Control  DVCS good - Git(Hub), several alternatives  Avoid old tech (svn, cvs, vss)  Embrace branching, merging, regular commits  Fork other peoples repos  Pull new changes  Pull-request – send your improvements upstream  Works with pippip install -e git+https://github.com/pinax/pinax-theme-bootstrap#egg=pinax-theme-bootstrap
  36. 36. Development tips
  37. 37. References Django  https://www.djangoproject.com/  http://djangopackages.com/ Pinax  http://pinaxproject.com/ & http://pinaxproject.com/ecosystem/  https://github.com/pinax/pinax  http://pinaxproject.com/blog/2011/10/10/djangocon-talk-pinax-after-three-years My apps/code  http://bit.ly/morebetterer  http://nowandthen.mindsocket.com.au/  https://github.com/mindsocket/ Twitter Bootstrap  http://twitter.github.com/bootstrap/
  38. 38. Q&A

×