Python中文
首页
教程
问答
标签
搜索
登录
注册
无法分析余数:“[plant\u id]”来自“total\u ecof[plant\u id]”
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我的<strong>视图.py</strong>:</p> <pre><code>def home(request): if not request.user.is_authenticated(): template = 'data/login.html' return render(request, template) else: plants = Plant.objects.filter(user=request.user) total_ecof = [] total_ectr = [] for plant in plants: x = 0 y = 0 for recording in Recording.objects.filter(plant__id=plant.id): x += (recording.time_to_detect * recording.performance_loss) / ( plant.nominal_power * recording.years_of_operation) y += ((10 + 15 + 200 + 50) * plant.no_modules + 240 * 50 * recording.occurrence * plant.no_modules) / ( plant.nominal_power * 3) total_ecof.append(x) total_ectr.append(y) template = 'data/home.html' context = { 'plants':plants, 'total_ecof':total_ecof, 'total_ectr':total_ectr, } return render(request, template, context) </code></pre> <p>我的html模板</p> <pre><code>{% for plant in plants %} <tr> <td>{{ plant.management_company }}</td> <td>{{ plant.plant_name }}</td> <td>{{total_ecof[plnat.id]}}</td> </tr> {% endfor %} </code></pre> <p>但我得到了一个错误:</p> <pre><code>Exception Type: TemplateSyntaxError Exception Value: Could not parse the remainder: '[plant.id]' from 'total_ecof[plant.id]' </code></pre> <p>我不明白为什么。我做错什么了?你知道吗</p> <p>此外,请你帮我创建一个条形图,其中x轴是植物,y轴是相应的总生态足迹。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>不要为总数创建单独的列表。创建一个由(record,total)对组成的列表,或者直接在录制实例上设置total。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
无法使用Django/mongoengine连接到MongoDB(身份验证失败)
6 回答
无法使用Django\u mssql\u后端迁移到外部hos
7 回答
无法使用Django&Python3.4连接到MySql
9 回答
无法使用Django+nginx上载媒体文件
2 回答
无法使用Django1.6导入名称模式
3 回答
无法使用Django1.7和mongodb登录管理站点
5 回答
无法使用Djangoadmin创建项目,进程使用了错误的路径,因为我事先安装了错误的Python
4 回答
无法使用Djangockedi验证CBV中的字段
3 回答
无法使用Djangocketditor上载图像(错误400)
5 回答
无法使用Djangocron进行函数调用
4 回答
无法使用Djangofiler djang上载文件
9 回答
无法使用Djangokronos
5 回答
无法使用Djangomssql provid
4 回答
无法使用Djangomssql连接到带有Django 1.11的MS SQL Server 2016
9 回答
无法使用Djangomssq迁移Django数据库
3 回答
无法使用Djangonox创建用户
8 回答
无法使用Djangopyodb从Django查询SQL Server
7 回答
无法使用Djangopython3ldap连接到ldap
8 回答
无法使用Djangoredis连接到redis
4 回答
无法使用Django中的FK创建新表
4 回答