Commit 0b066048 by Nicoly Aparecida Lopes

nicoly

parents 35d3516c 0287e5c9
......@@ -9,13 +9,28 @@ db.init_app(app)
with app.app_context():
db.create_all()
# LISTAR (página inicial)kjk
# 👤 BEATRYZ — LISTAR
@app.route('/')
def index():
animais = Animal.query.all()
return render_template('index.html', animais=animais)
# EDITAR (Nicoly)
# 👤 DUDA — CADASTRAR
@app.route('/cadastrar', methods=['GET', 'POST'])
def cadastrar():
if request.method == 'POST':
novo = Animal(
nome=request.form['nome'],
especie=request.form['especie'],
idade=int(request.form['idade']),
peso=float(request.form['peso'])
)
db.session.add(novo)
db.session.commit()
return redirect('/')
return render_template('cadastrar.html')
# 👤 NICOLY — EDITAR
@app.route('/editar/<int:id>', methods=['GET', 'POST'])
def editar(id):
animal = Animal.query.get(id)
......@@ -31,5 +46,15 @@ def editar(id):
return render_template('editar.html', animal=animal)
# 👤 WERICA — EXCLUIR
@app.route('/excluir/<int:id>')
def excluir(id):
animal = Animal.query.get(id)
db.session.delete(animal)
db.session.commit()
return redirect('/')
if __name__ == '__main__':
app.run(debug=True)
\ No newline at end of file
app.run(debug=True)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment