Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20 Django tips in 10 minutes

20 Django tips in 10 minutes

A lightning talk I gave at a mixed developer conference for those people starting out in Django

Aaron Bassett

May 07, 2011
Tweet

More Decks by Aaron Bassett

Other Decks in Programming

Transcript

  1. >>> connection.queries [{'time': '0.002', 'sql': u'SELECT `auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`,

    `auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`is_superuser`, `auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user` LIMIT 21'}]
  2. class Hello(Tag): options = Options( Argument('name', required=False, default='world'), 'as', Argument('varname',

    required=False, resolve=False) ) def render_tag(self, context, name, varname): output = 'hello %s' % name if varname: context[varname] = output return '' return output register.tag(Hello)
  3. class Hello(Tag): options = Options( Argument('name', required=False, default='world'), 'as', Argument('varname',

    required=False, resolve=False) ) def render_tag(self, context, name, varname): output = 'hello %s' % name if varname: context[varname] = output return '' return output register.tag(Hello)
  4. class Hello(Tag): options = Options( Argument('name', required=False, default='world'), 'as', Argument('varname',

    required=False, resolve=False) ) def render_tag(self, context, name, varname): output = 'hello %s' % name if varname: context[varname] = output return '' return output register.tag(Hello)
  5. all_blog_posts = Post.objects.all() p = Paginator(all_blog_posts, 10) try: cur_page =

    p.page(request.GET.get('page', 1)) except EmptyPage: raise Http404
  6. all_blog_posts = Post.objects.all() p = Paginator(all_blog_posts, 10) try: cur_page =

    p.page(request.GET.get('page', 1)) except EmptyPage: raise Http404
  7. all_blog_posts = Post.objects.all() p = Paginator(all_blog_posts, 10) try: cur_page =

    p.page(request.GET.get('page', 1)) except EmptyPage: raise Http404
  8. .,-:;//;:=, . :H@@@MM@M#H/.,+%;, ,/X+ +M@@M@MM%=,-%HMMM@X/, -+@MM; $M@@MH+-,;XMMMM@MMMM@+- ;@M@@M- XM@X;. -+XXXXXHHH@M@M#@/.

    ,%MM@@MH ,@%= .---=-=:=,. =@#@@@MX ., -%HX$$%%%+; =-./@M@M$ .;@MMMM@MM: X@/ -$MM/ .+MM@@@M$ ,@M@H: :@: . =X#@@@@- ,@@@MMX, . /H- ;@M@M= .H@@@@M@+, %MM+..%#$. /MMMM@MMH/. XM@MH; =; /%+%$XHH@$= , .H@@@@MX, .=--------. -%H.,@@@@@MX, .%MM@@@HHHXX$$$%+- .:$MMX =M@@MM%. =XMMM@MM@MM#H;,-+HMM@M+ /MMMX= =%@M@M#@$-.=$@MM@@@M; %M%= ,:+$+-,/H#MMMMMMM@= =, =++%%%%+/:-.