如何将两个变量从视图传递到Django中的html

时间:2013-01-30 07:17:44

标签: django django-forms django-templates django-views

我已将表中的对象变为2个变量。现在我想使用render_to_response将这些变量的值发送到html。

def AssetMovement(request):
    print "AssetMovement"
    feature_list = request.session['feature_list']
    featuresgroups = request.session['featuresgroups']
    pplid=request.session['pplid']
    empnm = Asset_Assignment_Employee.objects.filter(Employee__People=pplid)
    print empnm
    id_obj = Asset_Track.objects.all()
    print id_obj
    report = reports.astmvmt_repo(queryset=id_obj)
    report.generate_by(PDFGenerator, filename= 'E:\My Work Location\Example\WorkSpace\\asset_track1\media\\'+str(2)+".pdf")
    return render_to_response('asset_mgmt/astmvmtReport.html',{"contacts":feature_list,'root': settings.MEDIA_ROOT,'len':len(feature_list)-1,"featuresgroups":featuresgroups,'assertlist':id_obj})

如上所述,我已通过'assertlist'发送id_obj,现在我想发送同名的empnm对象,即'assertlist'并显示在表中。

请尽快回答这个问题。谢谢。

1 个答案:

答案 0 :(得分:0)

除上述评论外,另一个选项是使用{% with %}模板标记重新分配变量:https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#with