0

在HTML文件中总提示{%for i in range(10)%} 错误,请问是什么原因?

            {% for a in range(10) %}#此处出错
            <div class="fh5co-entry padding">
                <img src="/blogjs/images/project-1.jpg" alt="Free HTML5 Bootstrap Template by FreeHTML5.co">
                <div>
                    <span class="fh5co-post-date">October 12, 2016</span>
                    <h2><a href="/blogjs/single.html">How to be an effective web developer</a></h2>
                    <p>How two simple exercises changed my life</p>
                </div>
            </div>
            {% endfor %}

错误提示如下:

浏览器错误提示如下:

TemplateSyntaxError at /index/

Could not parse the remainder: '(10)' from 'range(10)'

Request Method:     GET
Request URL:     http://localhost:8000/index/
Django Version:     1.11.4
Exception Type:     TemplateSyntaxError
Exception Value:     

Could not parse the remainder: '(10)' from 'range(10)'

Exception Location:     /Library/Python/2.7/site-packages/django/template/base.py in parse, line 515
Python Executable:     /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version:     2.7.10
Python Path:     

['/Users/eric/Desktop/sundyblog',
 '/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg',
 '/Users/eric/Desktop/sundyblog',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/Library/Python/2.7/site-packages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

Server time:     Sat, 12 Aug 2017 13:53:15 +0000

1 个回答

0

已采纳

django的模板中并不支持range
如果你需要使用的话的几种方式实现
1.for i in "xxxxx"要几次就写几个x
2.在views里返回range
3.使用自定义filter