1

视图.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 错误,错误是“Caught VariableDoesNotExist while rendering: Failed lookup for key [time_filter] in u'[{}”

4

1 回答 1

3

您没有包含time_filterdate_filter在您传递给的上下文字典中render_to_response

于 2013-05-09T14:43:03.490 回答