英文:
**TemplateSyntaxError at /shop/** Could not parse the remainder: '[1:]' from 'product[1:]
问题
以下是我index.html的代码链接:
https://gist.github.com/MahdinOhi/b083179a8261b1d89291b69f6d66d5c8
对于这段代码,我遇到了以下错误:TemplateSyntaxError at /shop/ 无法解析剩余部分:'[1:]' 从 'product[1:]',而且我的轮播卡片显示不正确(我认为是CSS的问题)。以下是我遇到的错误(以Jpg格式显示):
我想从数据库中获取产品名称和图片。我需要解决这个错误。我想改进我的CSS。
英文:
The following link is the gist link of my index.html
https://gist.github.com/MahdinOhi/b083179a8261b1d89291b69f6d66d5c8
This was my code of index.html I am getting this error for this code: TemplateSyntaxError at /shop/ Could not parse the remainder: '[1:]' from 'product[1:] And also My carousel's card is not in a proper way (I think it's the fault of CSS) Here is the error I am getting (In Jpg):
I want to fetch the product names and images from the database.
I need to troubleshoot the error. I want to make better my CSS.
答案1
得分: 1
问题出在
{% for i in product[1:] %}
.....
{% endfor %}
product[1:]
这部分在 Django 模板中不被直接支持。相反,你可以尝试使用 slice
{% for i in product|slice:"1:" %}
... 你模板的其余部分
{% endfor %}
英文:
The issue is with
{% for i in product[1:] %}
.....
{% endfor %}
product[1:]
this is not directly supported within django templates. Instead you can try slice
{% for i in product|slice:"1:" %}
... Rest of your template codes
{% endfor %}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论