Click here to Skip to main content
15,867,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys,
I'm trying to sum the rows of the products cost into the portfolio table, so I inserted a refresh button in my flask page to do that that calls this function.

I need the sum part to work, and then I can safely add the commit to the sqlite database...

But I get this error message:
404 - Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

What's the mistake I made, please?

What I have tried:

Python
#refresh portfolio stats
@app.route('/refresh/<product_table>', methods = ['GET', 'POST'])
def row_sums():
all_product_data = product_table.query.all()
all_portfolio_data = portfolio_table.query.filter(portfolio_table.portfolio_id == 1)

# list to store sums
portfolio_table.portfolio_cost_total = []

# go through each row in square
for row in product_table:

# variable to store row total
total = 0

# go through each item in row and add to total
for product_table.product_cost_total in row:
total += product_table.product_cost_total

# append the row's total to the output list
portfolio_table.portfolio_cost_total.append(total)

# return the output list
flash("Portfolio Refresh Success!")
return portfolio_table.portfolio_cost_total
Posted
Updated 21-Jan-21 18:26pm

The URL is wrong. There is no URL in your code, ergo, your code is not the issue. You need instead to use your debugger.

Why on earth would you not calculate this with sql using SUM?
 
Share this answer
 
Comments
pythonHumanBot 21-Jan-21 19:22pm    
I'm confused, I have the same for my delete button but no URL issue, why do I have with almost the same steps?

#delete a product from the table
@app.route('/delete/', methods = ['GET', 'POST'])
def delete():
my_data = product_table.query.get(id)
db.session.delete(my_data)
db.session.commit()
flash("Stock/ETF Deleted Successfully")
return redirect(url_for('Index'))

Also, for the SQL, you mean:
SELECT
sum(portfolio_cost_total)
FROM
portfolio_table;
Christian Graus 21-Jan-21 19:23pm    
That code at least contains a URL. Are you stepping through the code? which line has the issue?
pythonHumanBot 21-Jan-21 19:32pm    
I'm genuinely confused... Here is the refresh button in index:


What am I missing in all this, please?

Also, the debugger just shows:
127.0.0.1 - - [21/Jan/2021 19:29:35] "GET /refresh/False HTTP/1.1" 404 -
Christian Graus 21-Jan-21 19:35pm    
So you called refresh/False with a get, and it failed
Maciej Los 22-Jan-21 5:37am    
5ed!
I changed the button from a href to bootstrap modal fixed the 404 error, thank you again Christian!
 
Share this answer
 
Comments
Maciej Los 22-Jan-21 5:37am    
Such of content should be posted as a comment. So, i'd suggest to detele "solution" which doesn't seem to be solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900