1

我的views.py 文件中有这个方法,它打印从方法rangeOfList() 返回的列表。
我想在将浏览器重定向到(result.html)的html页面上显示它。我该怎么写?

def contact(request):
if request.method == 'POST': # If the form has been submitted...
    form = ContactForm(request.POST) # A form bound to the POST data

    if form.is_valid():
        form = form.cleaned_data
        parameters = organize(form)
        listToPrint = rangeOfList(parameters['money'][2], parameters['money'][4], 'total_money')



    return HttpResponseRedirect('result') # Redirect after POST
else:
    form = ContactForm() # An unbound form

return render(request, 'crunchApp/contact.html', {
    'form': form,
})
4

1 回答 1

0

您应该将其添加到会话中

request.session['the_list'] = listToPrint
return redirect('result/')

确保您已经激活了请求模板上下文处理器,然后在您的模板中:

{% for i in request.session.the_list %}
   {{ i }}
{% endfor %}
于 2012-08-30T19:02:08.323 回答