如何呈现回应? [英] how to render to response?

查看:85
本文介绍了如何呈现回应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用render_to_response将列表发送到模板。我正在使用django快捷方式。锄要这样做吗如何使用变量设置上下文实例?

解决方案

  from django.shortcuts import render_to_response 

def my_view(request):
mylist = ['item 1','item 2','item 3']

返回render_to_response('template.html ',{'mylist':mylist})

然后可以访问和枚举列表在这样的模板(除其他方法之外):

  {%for my in mylist %} 
{{i}},
{%endfor%}


I am sending list to a template using render_to_response. I am using django shortcuts. Hoe to do that? How to set context instance with a variable?

解决方案

from django.shortcuts import render_to_response

def my_view(request):
    mylist = ['item 1', 'item 2', 'item 3']

    return render_to_response('template.html', {'mylist':mylist})

You can then access and enumerate list in the template like this (amongst other methods):

{% for i in mylist %}
   {{ i }}, 
{% endfor %}

这篇关于如何呈现回应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆