Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
722 views
in Technique[技术] by (71.8m points)

python - jinja2.exceptions.UndefinedError: 'None' has no attribute 'emptyweight'

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...