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
Compose でデザインと実装の差異を減らすための取り組み
oidy
1
300
技術を根付かせる / How to make technology take root
kubode
1
240
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
0
180
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
130
DROBEの生成AI活用事例 with AWS
ippey
0
130
ARA Ansible for the teams
kksat
0
150
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
7
2.5k
Rails アプリ地図考 Flush Cut
makicamel
1
110
Formの複雑さに立ち向かう
bmthd
1
720
Domain-Driven Transformation
hschwentner
2
1.9k
2,500万ユーザーを支えるSREチームの6年間のスクラムのカイゼン
honmarkhunt
6
5.1k
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
8
2.6k
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Navigating Team Friction
lara
183
15k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Speed Design
sergeychernyshev
25
780
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.8k
A Philosophy of Restraint
colly
203
16k
Raft: Consensus for Rubyists
vanstee
137
6.8k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
31
2.1k
The Cult of Friendly URLs
andyhume
78
6.2k
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