Django检索GET列表 [英] Django retrieve GET list
本文介绍了Django检索GET列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Django的新手,并且有一个URL列表,例如:
I'm new with Django and I have a URL list such as:
example.com?item=test&item=for&test=url
我知道如何在视图中检索此值:
I know how to retrieve this value in the view:
a = request.GET.getlist('item')
我的问题是:如何在模板中检索此列表?
My problem is: How can I retrieve this list in the template?
谢谢!
推荐答案
您需要通过模板上下文传递给模板.
You need to pass to template through template context.
例如
def myview(request):
a = request.GET.getlist('item')
...
ctx = {'myitems': a}
return render(request, 'your_template.html', ctx)
在模板中:
{% for item in myitems %}
<p>{{ item }}</p>
{% endfor %}
这篇关于Django检索GET列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文