I'm building a table from values in my database. A couple of the columns I have need to be summed from one value of a database to another value in a different database. I'm able to pull from each of my databases perfectly fine and populate my table. The problem I run into, is when I try to sum each of the different values, I get the error
jinja2.exceptions.UndefinedError: 'None' has no attribute 'emptyweight'
When I run the below code, everything works as I need it to.
{% for car in yardDB %}
<tr>
<td>{{car.loadWeightUSTons}}</td>
<td>{{CarDB.query.filter_by(rvXMLfilename=car.rvXMLfilename).first().emptyweight}}</td>
</tr>
{% endfor %}
The problem occurs when I try to sum each of those 2 values from the databases.
{% for car in yardDB %}
<tr>
<td>{{car.loadWeightUSTons + CarDB.query.filter_by(rvXMLfilename=car.rvXMLfilename).first().emptyweight}}</td>
</tr>
{% endfor %}
Things to Note:
- I am passing in all the variables I need to access the databases.
- The values I'm pulling are both integers.
- I've tried adding a fixed number to either one of the returned values in the first code block, and it works fine. (example: I've added '+100' inside code and it adds the database values plus 100)
question from:
https://stackoverflow.com/questions/65650753/jinja2-exceptions-undefinederror-none-has-no-attribute-emptyweight 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…