When I was testing my site in localhost, everything worked fine. Its a simple stock management program, you insert the item id and the number of remaining items, but what's happening is that when I change something and reload the page which displays the items list, the changes aren't applied.
Im gonna paste the code here since it isn't very important
from flask import Flask, render_template, url_for, flash, request, redirect
import os
import pandas as pd
from os import urandom
df = pd.read_csv('estoque.csv')
print(df)
app = Flask(__name__)
app.secret_key = urandom(24)
@app.route('/', methods=['GET'])
def index():
try:
os.remove('templates/aaaa.html')
except:
pass
df.to_html('templates/aaaa.html')
return render_template('index.html')
@app.route('/novo', methods=['GET', 'POST'])
def novo():
global df
if request.method == 'POST':
nome = request.form['nome']
numero = request.form['numero']
if not nome:
flash('Não inseriu o nome do item')
return render_template('novo_item.html')
if not numero:
flash('Não inseriu o numero')
return render_template('novo_item.html')
else:
df.loc[len(df), 'item'] = nome
df.loc[len(df)-1, 'numero'] = numero
df = df.sort_values(by=['item'])
df.to_csv('estoque.csv', index=False)
return render_template('novo_item.html')
else:
return render_template('novo_item.html')
@app.route('/inventario', methods=['GET'])
def tabela():
try:
os.remove('templates/aaaa.html')
except:
pass
df.to_html('templates/aaaa.html')
return render_template('aaaa.html')
@app.route('/registro', methods=['GET', 'POST'])
def registro():
if request.method == 'POST':
idd = request.form['id']
numero = request.form['numero']
if not idd:
flash('Não inseriu o item')
return render_template('registro.html')
if not numero:
flash('Não inseriu o numero')
return render_template('registro.html')
else:
for row in range(0, len(df)):
print(row, idd)
if row==int(idd):
df.loc[row, 'numero'] = numero
print('\n', df.loc[row, 'numero'], '\n')
df.to_csv('estoque.csv', index=False)
return render_template('registro.html')
else:
return render_template('registro.html')
if __name__ == '__main__':
app.run(debug=True)
I'm probably doing something extremely stupid, it's my first web app and I don't know my way through it very well yet. Thanks a lot