views.py
def when(request):
user = request.user
report = Report.objects.get(user=request.user)
reportform = ReportForm(instance=report)
settings = Settings.objects.get(user=request.user)
settingsForm = SettingsForm(instance=settings)
settings=Settings.objects.get(user=2)
if settings.date_format == '0':
date_filter = 'd/m/Y'
else:
date_filter = 'm/d/Y'
if settings.time_format == '0':
time_filter = 'I:Mp'
else:
time_filter = 'H:M'
if request.method == 'POST':
reportform = ReportForm(instance=report,data=request.POST)
if reportform.is_valid():
report = reportform.save(commit=False)
report.user = request.user
report.save()
return redirect('/member/media/')
return render_to_response('incident/when.html',{
'newreport_menu': True,
'form': reportform,
},
context_instance=RequestContext(request))
模板是
{{ form.manual_time|date:time_filter }}
{{ form.manual_date|date:date_filter }}
在模板中的date_filter和time_filter中给出错误,错误是“在渲染时捕获VariableDoesNotExist:在['{}}中找到关键[time_filter]的失败,
答案 0 :(得分:3)
您尚未在传递给time_filter
的上下文词典中添加date_filter
或render_to_response
。