Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django template is not displaying

Assuming my model contains data, I have myapp/views.py:

from django.template import RequestContext
from django.shortcuts import render
from .models import History
import datetime

def live_view(request):
    context = RequestContext(request)
    plays_list = History.objects.filter(date=datetime.date(2016,04,22))
    context_list = {'plays':plays_list}
    return render(request,'live.html',context_list)

myapp/templates/live.html:

{% extends 'base.html' %}
{% block content %}
{% for key, value in context_list.items %}
    {{ value }}
{% endfor %}
{% endblock %}

myapp/urls.py:

from myapp.views import live_view

urlpatterns = [url(r'^live/$', live_view, name="live"),]

The output is a page that renders only the base.html template, with no content in the body. What's wrong with my view function or template rendering? Should I be inheriting from TemplateView?

like image 928
DNburtonguster Avatar asked Oct 24 '25 18:10

DNburtonguster


1 Answers

You don't pass anything called context_list to the template. What you pass is the contents of that dict, which in this case is just plays.

like image 114
Daniel Roseman Avatar answered Oct 26 '25 10:10

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!