Модель и представление
из flask импорт Flask из flask_sqlalchemy import SQLAlchemy
class account (db.Model):
id = db.Column(db.Integer,primary_key=True)
amount = db.Column(db.BigInteger,default=0)
today=db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
@app.route('/office' , methods=['GET', 'POST'])
def office():
funds = account.query.all()
for fund in funds:
print (fund.amount)
Этот код работает без ошибок, перечисляя всю сумму в базе данных, но если я следует добавить сумму ко второму коду, это выдает ошибку
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://localhost:7000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 263-984-974
5247065
5247065
5247065
5247065
127.0.0.1 - - [10/Feb/2020 16:02:59] "GET /office HTTP/1.1" 200 -
Я пытаюсь сложить весь список вместе, чтобы получить итоговую итоговую сумму.
@app.route('/office' , methods=['GET', 'POST'])
def office():
funds = account.query.all()
for fund in funds:
print (sum(fund.amount))
выдает ошибку.
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://localhost:7000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 263-984-974
127.0.0.1 - - [10/Feb/2020 16:08:50] "GET /office HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/blazskills/.local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/blazskills/Documents/tacgwarimpalatest/app.py", line 205, in office
print (sum(fund.amount))
TypeError: 'int' object is not iterable
127.0.0.1 - - [10/Feb/2020 16:08:50] "GET /office?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [10/Feb/2020 16:08:50] "GET /office?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [10/Feb/2020 16:08:50] "GET /office?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [10/Feb/2020 16:08:50] "GET /office?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [10/Feb/2020 16:08:50] "GET /office?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -