Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Some random Django tips

adrianholovaty
September 05, 2013

Some random Django tips

My lightning talk from DjangoCon Chicago 2013.

adrianholovaty

September 05, 2013
Tweet

More Decks by adrianholovaty

Other Decks in Technology

Transcript

  1. <body> {% if USER %} Logged in as {{ USER.username

    }} {% else %} <a href=”/login/”>Log in</a> {% endif %} {% for item in items %} <p>{{ item.name }}</p> {% endfor %} </body>
  2. <body> {% if USER %} Logged in as {{ USER.username

    }} {% else %} <a href=”/login/”>Log in</a> {% endif %} {% for item in items %} <p>{{ item.name }}</p> {% endfor %} </body>
  3. <body> {% raw %} {% if USER %} Logged in

    as {{ USER.username }} {% else %} <a href=”/login/”>Log in</a> {% endif %} {% endraw %} {% for item in items %} <p>{{ item.name }}</p> {% endfor %} </body>
  4. qs = Song.objects.filter(artist=‘Django’) if request.user: qs = qs.filter(user_id=request.user.id) kwargs =

    {‘artist’: ‘Django’} if request.user: kwargs[‘user_id’] = request.user.id qs = Song.objects.filter(**kwargs)
  5. urlpatterns = patterns(‘’, # ... (r'^(?P<src>yt|pro)/(?P<sid>[-_\w]{1,35})/', include(patterns('', (r'^api/$', views.song_api), (r'^edit/$',

    views.song_edit_form), (r'^clear-bars/$', views.clear_bars), (r'^delete/$', views.song_delete), ))), ) urlpatterns = patterns(‘’, # ... (r'^(yt|pro)/([-_\w]{1,35})/api/$', views.song_api), (r'^(yt|pro)/([-_\w]{1,35})/edit/$', views.song_edit_form), (r'^(yt|pro)/([-_\w]{1,35})/clear-bars/$', views.clear_bars), (r'^(yt|pro)/([-_\w]{1,35})/delete/$', views.song_delete), )