Python语法问题
在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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
django的模板中并不支持range
如果你需要使用的话的几种方式实现
1.for i in "xxxxx"要几次就写几个x
2.在views里返回range
3.使用自定义filter