Django模板没有显示

时间:2016-06-03 15:35:32

标签: django django-templates

假设我的模型包含数据,我有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 /模板/ 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"),]

输出是一个只呈现base.html模板的页面,主体中没有内容。我的视图函数或模板渲染有什么问题?我应该继承自TemplateView吗?

1 个答案:

答案 0 :(得分:2)

您不会将名为context_list的任何内容传递给模板。你传递的是该词典的内容,在这种情况下只是plays