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
250
Hello to the World in 8 Web Frameworks (Micro, Batteries Included & Async)
aaronbassett
0
51
When The __future__ Becomes The Present; Dropping Python 2 Support In A Commercial Client
aaronbassett
1
59
Real-time transcription and sentiment analysis of audio streams; on the phone and in the browser
aaronbassett
0
75
Django and the testing pyramid - DjangoCon Europe 2017
aaronbassett
0
760
Avoiding the "left-pad" problem: How to secure your pip install process
aaronbassett
0
350
Sun, Sea & Pi - A Raspberry Pi day talk
aaronbassett
0
120
Having fun with testing
aaronbassett
0
55
Other Decks in Programming
See All in Programming
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
200
testcontainers のススメ
sgash708
1
130
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
300
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
8
1.9k
良いユニットテストを書こう
mototakatsu
8
3.1k
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
230
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
5
930
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
190
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
33
1.5k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
910
Testing 201, or: Great Expectations
jmmastey
41
7.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Automating Front-end Workflow
addyosmani
1366
200k
Producing Creativity
orderedlist
PRO
342
39k
Code Review Best Practice
trishagee
65
17k
Side Projects
sachag
452
42k
BBQ
matthewcrist
85
9.4k
Statistics for Hackers
jakevdp
796
220k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
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