Django:在数据视图中添加新字段

时间:2014-11-05 09:35:59

标签: python django

全部你好!我使用get _ context _ data

class YourDetailView(DetailView):
    context_object_name = "quizli"
    model = Quizli

    def get_context_data(self, **kwargs):       
        context = super(YourDetailView, self).get_context_data(**kwargs)
        context["ll"]  = 33
        return context

..................................
......................................

url(r'^(?P<pk>\d+)$', YourDetailView.as_view(
                template_name="quiz.html")),
模板中的

len: <div class="quest">{{ object.ll}}</div>

而不是33,请返回“”请帮助

1 个答案:

答案 0 :(得分:1)

上下文变量名为ll,而不是object.ll。因此,请尝试:

<div class="quest">{{ ll }}</div>