Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
20 Django tips in 10 minutes
Search
Aaron Bassett
May 07, 2011
Programming
0
92
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
Share
More Decks by Aaron Bassett
See All by Aaron Bassett
When your wetware has too many threads - Tips from an ADHDer on how to improve your focus
aaronbassett
1
55
Stupid (and possibly illegal) stuff you can do with SMS, but probably shouldn't
aaronbassett
0
270
Hello to the World in 8 Web Frameworks (Micro, Batteries Included & Async)
aaronbassett
0
52
When The __future__ Becomes The Present; Dropping Python 2 Support In A Commercial Client
aaronbassett
1
62
Real-time transcription and sentiment analysis of audio streams; on the phone and in the browser
aaronbassett
0
76
Django and the testing pyramid - DjangoCon Europe 2017
aaronbassett
0
790
Avoiding the "left-pad" problem: How to secure your pip install process
aaronbassett
0
360
Sun, Sea & Pi - A Raspberry Pi day talk
aaronbassett
0
120
Having fun with testing
aaronbassett
0
58
Other Decks in Programming
See All in Programming
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
490
TokyoR116_BeginnersSession1_環境構築
kotatyamtema
0
110
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
0
170
Domain-Driven Transformation
hschwentner
2
1.9k
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
130
『品質』という言葉が嫌いな理由
korimu
0
160
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
5
3.8k
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
480
SRE、開発、QAが協業して挑んだリリースプロセス改革@SRE Kaigi 2025
nealle
3
4.1k
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
110
時計仕掛けのCompose
mkeeda
1
280
技術を根付かせる / How to make technology take root
kubode
1
240
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
34
3.1k
Why Our Code Smells
bkeepers
PRO
335
57k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Faster Mobile Websites
deanohume
306
31k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
12
950
The World Runs on Bad Software
bkeepers
PRO
67
11k
Navigating Team Friction
lara
183
15k
Optimizing for Happiness
mojombo
376
70k
Statistics for Hackers
jakevdp
797
220k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Transcript
20 Django tips in 10 minutes
www.thisislevelup.com | @thisislvlup
www.thisislevelup.com | @thisislvlup
{% DEBUG %} 1.
None
None
‘debug_toolbar’ 2.
None
https:/ /github.com/robhudson/ django-debug-toolbar
assert False 3.
None
if qs.exists(): 4.
all_users = User.objects.all() if all_users: # Do some stuff
>>> 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'}]
all_users = User.objects.all() if all_users.exists(): # Do some stuff
>>> connection.queries [{'time': '0.001', 'sql': u'SELECT (1) AS `a` FROM
`auth_user` LIMIT 1'}]
def get_absolute_url(self): 5.
{{ blog_post.get_absolute_url }} {{ news_article.get_absolute_url }} {{ user_profile.get_absolute_url }} {{
product.get_absolute_url }} {{ ddd_talk.get_absolute_url }}
{{ blog_post.get_absolute_url }} {{ news_article.get_absolute_url }} {{ user_profile.get_absolute_url }} {{
product.get_absolute_url }} {{ ddd_talk.get_absolute_url }}
{% url ddd.views.profile 28 %} 6.
def get_absolute_url(self): 5.
def get_absolute_url(self): 5.
{{ block.super }} 7.
<title>{% block title %}DDD Scotland{% endblock %}</title>
{% block title %}{{ block.super }} - {{ article.title }}
{% endblock %}
{% classy_tags %} 8.
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)
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)
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)
https:/ /github.com/ojii/ django-classy-tags
from django.core.paginator import Paginator 9.
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
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
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
@render_to 10.
def foo(request): bar = Bar.object.all() return render_to_response('template.html', {'bar': bar}, context_instance=RequestContext(request))
@render_to('template.html') def foo(request): bar = Bar.object.all() return {'bar': bar}
https:/ /bitbucket.org/ offline/django-annoying
@cache_page 11.
@cache_page(60 * 15) def my_view(request): ...
{% cache %} 12.
{% cache 300 nav %} {% show_menu %} {% endcache
%}
__init__.py 13.
None
None
None
django.contrib.admindocs 14.
None
None
None
None
None
'django_extensions' 15.
./manage.py shell_plus
http:/ /code.google.com/p/ django-command-extensions/
./manage.py graph_models 16.
None
pip install django-admin-tools 17.
None
None
None
https:/ /bitbucket.org/ izi/django-admin-tools/
localsettings.py 18.
None
os.path.dirname() 19.
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')
SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) MEDIA_ROOT = os.path.join(SITE_ROOT, 'media') TEMPLATE_DIRS = (
os.path.join(SITE_ROOT, 'template') )
Have fun. 20.
.,-:;//;:=, . :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@= =, =++%%%%+/:-.
{% delicious_cake %}
None
THANK YOU!
THANK YOU! @aaronbassett
THANK YOU! @aaronbassett @thisislvlup