Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get template working in django?
    primarykey
    data
    text
    <p>I was on the 3rd tutorial of this <a href="https://docs.djangoproject.com/en/1.5/intro/tutorial03/" rel="nofollow">https://docs.djangoproject.com/en/1.5/intro/tutorial03/</a> site. I got stuck where we load template for our views under the section <code>Write views that actually do something</code>.</p> <p>The first code is working fine ( as there is no template loading):</p> <pre><code> from django.http import HttpResponse from polls.models import Poll def index(request): latest_poll_list = Poll.objects.order_by('-pub_date')[:5] output = ', '.join([p.question for p in latest_poll_list]) return HttpResponse(output) </code></pre> <p>But when I laod the template with code below it shows same result as above( that is with no template)</p> <pre><code>from django.http import HttpResponse from django.template import Context, loader from polls.models import Poll def index(request): latest_poll_list = Poll.objects.order_by('-pub_date')[:5] template = loader.get_template('polls/index.html') context = Context({ 'latest_poll_list': latest_poll_list, }) return HttpResponse(template.render(context)) </code></pre> <p>The template use is:</p> <pre><code>{% if latest_poll_list %} &lt;ul&gt; {% for poll in latest_poll_list %} &lt;li&gt;&lt;a href="/polls/{{ poll.id }}/"&gt;{{ poll.question }}&lt;/a&gt;&lt;/li&gt; {% endfor %} &lt;/ul&gt; {% else %} &lt;p&gt;No polls are available.&lt;/p&gt; {% endif %} </code></pre> <p>The template is in polls/template/polls/index.html where polls is my app( as used in tutorial) <br> PS:I have followed everything as it is till this point from tutorial.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload