intro to pinax: kickstarting your django apps
DESCRIPTION
Presented at Sydney Python Users Group November 2011TRANSCRIPT
![Page 1: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/1.jpg)
Intro to PinaxKickstarting Your Django Apps
SyPy - November 2011
Roger Barnes @[email protected] http://gplus.to/mindsocket
![Page 2: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/2.jpg)
Who am I
Roger Barnes BTech ICS
By day: Tech Lead/Applications Developer Java :(
By night: Up and coming Python ninja
![Page 3: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/3.jpg)
Topics
Intro to Django Intro to Pinax Alternatives Development Tips Q&A
![Page 4: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/4.jpg)
What is Django
”The web framework for perfectionists with deadlines”
Initially developed in an online news environment
Designed for rapid development
![Page 5: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/5.jpg)
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, ...
![Page 6: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/6.jpg)
Django is...
… really well documented
https://docs.djangoproject.com
![Page 7: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/7.jpg)
Example: More Betterer
My first Django app Goal 1: Learn some Python and Django Goal 2: Find out what photos people liked
![Page 8: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/8.jpg)
Example: More Betterer
Very simple models Item (an image) Challenge (a showdown between 2 items)
Item manager counts challenge votes provides ordered list
![Page 9: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/9.jpg)
Lessons from 1st Django app
Django alone isn't 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 aren't obvious or are evolving (eg class-based views in 1.3)
So...
![Page 10: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/10.jpg)
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)
![Page 11: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/11.jpg)
What is Pinax
Social friendly Comments Voting Notifications Profiles/Accounts/OAuth ...
Startup friendly Private beta Invite codes Starter projects
![Page 12: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/12.jpg)
When to use Pinax
Great for building and maintaining multiple sites … quickly
Not as much benefit for a big enterprise app
![Page 13: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/13.jpg)
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
![Page 14: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/14.jpg)
Example: Now and Then
An application for aligning and overlaying historical images with modern equivalents
![Page 15: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/15.jpg)
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
![Page 16: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/16.jpg)
Example: Now and Then
![Page 17: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/17.jpg)
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
![Page 18: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/18.jpg)
Pinax - Layout
|-- apps| |-- about| | |-- models.py| | |-- urls.py| | |-- views.py| |-- my_foo_app| | |-- ... | |-- ...| | |-- ... |-- deploy| |-- pinax.fcgi| `-- pinax.wsgi|-- dev.db
|-- fixtures| `-- initial_data.json|-- locale| |-- ...|-- manage.py|-- media| |-- css| | `-- site_tabs.css| |-- ...|-- requirements| |-- base.txt| `-- project.txt|-- settings.py|-- templates| |-- about| |-- account| |-- ...|-- tests| |-- ...|-- urls.py
![Page 19: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/19.jpg)
Pinax
Requirements (pip) Base
what pinax needs Project
what you want to add
For Now and Then:
PILaino-convertdjango-extensionsdjango-memcache-statusdjango-jenkinsseleniumpyvirtualdisplayMySQL-pythonpython-memcachedflickrapisouthdjango-taggingdjango-votingPyYAMLnltkminidetectorgeopy
![Page 20: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/20.jpg)
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
![Page 21: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/21.jpg)
Pinax
Starter projects zero basic account static private_beta cms_company intranet social cms_holidayhouse company sample_group code
![Page 22: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/22.jpg)
Pinax
Fairly well documentedhttp://pinaxproject.com/docs/
Code on github
![Page 23: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/23.jpg)
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/
![Page 24: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/24.jpg)
Pinax isn't
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
![Page 25: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/25.jpg)
Pinax – Idea to Launch
The next big social networkmytweetbooktubelyplus.com
Domain name is not currently registered. Available for you now!
![Page 26: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/26.jpg)
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”
![Page 27: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/27.jpg)
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!
![Page 28: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/28.jpg)
Alternatives to Pinax
Hand-pick your own bundled apps PyPI Djangopackages.com
Other starter projects on github Eg: django-party-pack
![Page 29: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/29.jpg)
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 django's management tools
![Page 30: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/30.jpg)
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
![Page 31: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/31.jpg)
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/')
![Page 32: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/32.jpg)
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 …
![Page 33: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/33.jpg)
Dev tips - Continuous Integration
Jenkins unittest2
django-jenkins
coverage
Build triggered by commit (or polled)
![Page 34: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/34.jpg)
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
![Page 35: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/35.jpg)
Development tips – Source Control
DVCS good - Git(Hub), several alternatives Avoid old tech (svn, cvs, vss) Embrace branching, merging, regular commits Fork other people's repos
Pull new changes Pull-request – send your improvements upstream
Works with pip
pip install -e git+https://github.com/pinax/pinax-theme-bootstrap#egg=pinax-theme-bootstrap
![Page 36: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/36.jpg)
Development tips
![Page 37: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/37.jpg)
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/
![Page 38: Intro to Pinax: Kickstarting Your Django Apps](https://reader034.vdocument.in/reader034/viewer/2022051608/540698cf8d7f72b90a8b4679/html5/thumbnails/38.jpg)
Q&A