snipt

Ctrl+h for KB shortcuts

Django/Jinja

Bit of the poll tutorial from djangoproject.com

1
2
3
4
5
6
from django.shortcuts import render_to_response
from mysite.polls.models import Poll

def index(request):
    latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
    return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})
https://snipt.net/embed/3671370d42f5dda212c92d3b2453e4ef/
/raw/3671370d42f5dda212c92d3b2453e4ef/
3671370d42f5dda212c92d3b2453e4ef
django
Django/Jinja
6
2019-07-07T04:52:41
True
False
False
/api/public/snipt/2289/
bit-of-the-poll-tutorial-from-djangoprojectcom
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">from django.shortcuts import render_to_response</span> </span><span id="L-2"><a name="L-2"></a><span class="x">from mysite.polls.models import Poll</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="x">def index(request):</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> latest_poll_list = Poll.objects.all().order_by(&#39;-pub_date&#39;)[:5]</span> </span><span id="L-6"><a name="L-6"></a><span class="x"> return render_to_response(&#39;polls/index.html&#39;, {&#39;latest_poll_list&#39;: latest_poll_list})</span> </span></pre></div> </td></tr></table>
django