ビュー.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 をキャッチ: u'[{} でキー [time_filter] のルックアップに失敗しました」です。