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
50
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
50
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
71
Django and the testing pyramid - DjangoCon Europe 2017
aaronbassett
0
750
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
110
Having fun with testing
aaronbassett
0
54
Other Decks in Programming
See All in Programming
Click-free releases & the making of a CLI app
oheyadam
2
120
Outline View in SwiftUI
1024jp
1
340
カンファレンスの「アレ」Webでなんとかしませんか? / Conference “thing” Why don't you do something about it on the Web?
dero1to
1
110
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Jakarta EE meets AI
ivargrimstad
0
200
React への依存を最小にするフロントエンド設計
takonda
12
3.6k
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
910
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.8k
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
150
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1.1k
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
6
1.6k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
169
14k
Making Projects Easy
brettharned
115
5.9k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Ruby is Unlike a Banana
tanoku
97
11k
Fireside Chat
paigeccino
34
3k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
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