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
93
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
56
Stupid (and possibly illegal) stuff you can do with SMS, but probably shouldn't
aaronbassett
0
280
Hello to the World in 8 Web Frameworks (Micro, Batteries Included & Async)
aaronbassett
0
54
When The __future__ Becomes The Present; Dropping Python 2 Support In A Commercial Client
aaronbassett
1
63
Real-time transcription and sentiment analysis of audio streams; on the phone and in the browser
aaronbassett
0
77
Django and the testing pyramid - DjangoCon Europe 2017
aaronbassett
0
810
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
59
Other Decks in Programming
See All in Programming
GoとPHPのインターフェイスの違い
shimabox
2
200
Unity Android XR入門
sakutama_11
0
170
Writing documentation can be fun with plugin system
okuramasafumi
0
120
sappoRo.R #12 初心者セッション
kosugitti
0
260
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
180
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
280
負債になりにくいCSSをデザイナとつくるには?
fsubal
10
2.5k
バックエンドのためのアプリ内課金入門 (サブスク編)
qnighy
8
1.8k
ファインディLT_ポケモン対戦の定量的分析
fufufukakaka
0
860
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
810
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
160
Amazon S3 TablesとAmazon S3 Metadataを触ってみた / 20250201-jawsug-tochigi-s3tables-s3metadata
kasacchiful
0
180
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Designing for Performance
lara
604
68k
The Invisible Side of Design
smashingmag
299
50k
A designer walks into a library…
pauljervisheath
205
24k
For a Future-Friendly Web
brad_frost
176
9.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
We Have a Design System, Now What?
morganepeng
51
7.4k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Producing Creativity
orderedlist
PRO
344
39k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Scaling GitHub
holman
459
140k
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