Python语法问题

发布于 2022-09-05 09:38:09 字数 2496 浏览 8 评论 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪若未夕 2022-09-12 09:38:09

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文