Django:pythons os.scandir next()方法在模板内部不起作用 [英] Django: pythons os.scandir next() method not working inside template
本文介绍了Django:pythons os.scandir next()方法在模板内部不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在views.py中有以下代码
I have the following code in the views.py
def gallery(request):
import os, sys
img_list2 = os.scandir('/home/shared/testing')
return render(request,'blog/gallery.html', {'images2':img_list2})
它将迭代器img_list2发送到模板gallery.html
It is sending the iterator img_list2 to the template gallery.html
我的gallery.html如下
My gallery.html is as follows
<div>
<p>{{ next(images2).path }}</p>
</div>
我只是测试next()方法的工作与否。
I am just testing the next() method works or not.
它说
django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '(images2).path' from 'next(images2).path'
[13/Sep/2016 23:21:38] "GET /gallery/ HTTP/1.1" 500 13092
推荐答案
你没有使用Jinja2;您正在使用Django模板语言,其中无效的语法用参数调用函数。
You're not using Jinja2; you're using the Django template language, where it's invalid syntax to call functions with parameters.
这篇关于Django:pythons os.scandir next()方法在模板内部不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文