LinkedIn emplea cookies para mejorar la funcionalidad y el rendimiento de nuestro sitio web, así como para ofrecer publicidad relevante. Si continúas navegando por ese sitio web, aceptas el uso de cookies. Consulta nuestras Condiciones de uso y nuestra Política de privacidad para más información.
LinkedIn emplea cookies para mejorar la funcionalidad y el rendimiento de nuestro sitio web, así como para ofrecer publicidad relevante. Si continúas navegando por ese sitio web, aceptas el uso de cookies. Consulta nuestra Política de privacidad y nuestras Condiciones de uso para más información.
Disclaimer● This talk should take approximately 1 month● I dont always take my own advice● Im not an expert● Im going to forget something● You have a different opinion than me
A note on personal philosophy● Organization makes chaos manageable○ PEP8○ Code standards○ DRY○ Hierarchical organization lets me understand what Ineed to to solve the problem in front of me
A note on personal philosophy● Provide value with as few LOC as possible○ "Everything should be made as simple as possible,but not simpler"● "Unix Philosophy"○ Read "The Art of Unix Programming"○ Things should fail noisily○ Dont surprise me
README● Your project should have a README○ Seriously○ You want to go on vacation● Format it in some way thats easy to read○ duh● What should probably be there○ Installation instructions○ Design decisions○ Contribution information (or put this in a Contributing file)
Root project urls● If at all possible should only include apps urlpatternsfrom django.conf.urls import patterns, url, includeurlpatterns = patterns(project,url(rachievements/, include(achievements.urls)))
Settings● Recently weve started using environmentvariables with some success● Weve also used approaches where we havea settings directory whos __init__.py filedetermins appropriate settings forenvironment● Try to be organized, honestly, just use ENV
Project specific Code● As much as possible bundle code intoreusable apps● Things that might have to go here○ Custom test runners○ Project middlewares○ Project template context processors○ Functions that dont make sense elsewhere○ dbrouters
Application Tests● You should have tests○ TDD/BDD if possible○ IMHO your model tests / design give better ROI○ If you find a bug write a test to reproduce, fix○ Seriously testing will save you time○ Really○ Please
Models● Models are the lifeblood of your apps○ Start with model design first○ Design your data model well and views will comenaturally● Model Managers are pretty awesome○ Your views (controllers) should be able to call 1/2model manager methods in order to get what itneeds otherwise code needs to be refactored into amodel manager● Querysets can be subclassed as well○ can make view / task code much much easier○ DRY
Application Views● Make the views as simple as possible○ Template views can probably be functions that callrender○ If a view has lots of model calls that code canprobably go into a manager■ Manager are easier to test■ If managers have lots of interdependencies yourdata model probably needs to be refactored● Use django shortcuts when possible● IMHO template logic is ok to a point if itsimplifies view code, but dont go overboard
Tasty Pie● Dont re-invent the wheel● Tastypie is useful for most (but not all)RESTful applications● The code is already tested● You dont need as much control over JSONstructure as you think.● This is a separate talk, but be aware of it.
Background / Async in Django● There are lots of choices for this● ZMQ○ Lots of options for routing○ VERY flexible○ VERY fast○ VERY cool○ Django z-tasks looks promising○ BUT■ Have to write your own workers■ Have to write your own logging / monitoring■ Have to understand a fair amount to make it workcorrectly.■ SO...
Celery● Should be your default choice for async● Very simple python API○ Async tasks○ Tasks in the future○ Cron replacement● Workers are already written● Integrated with new relic○ Ops have been much easier for us○ Traceback monitoring major win
Application templates● Same as static files, namespace them● Use template inheritance○ DRY● Use named url patterns in your templates● Dont go overboard with template logic○ If you must check out template includes○ Huge templates are hard to read● Lots of view code data munging can bereplaced with template filters.● Django templates are really controllers○ Let templates act like views, handle presentation.
Other things you should be aware of● Middlewares● Class Based Views● Template Context Processors● Custom Template Tags
Django Apps that make me happy● Django Extensions○ Werkzeug● South○ Probably coming to Django 1.6
Tools you should use● Code Quality○ PEP8○ Pyflakes○ Pychecker○ jshint○ jslint● Development Environment○ ack-grep○ emacs :)● Infrastructure○ PGbouncer