Commit e3d831ad by Beatryz Chagas

beatryz

parent cbfbbe25
......@@ -9,24 +9,50 @@ db.init_app(app)
with app.app_context():
db.create_all()
# BEATRYZ — LISTAR
# 👤 BEATRYZ — LISTAR
@app.route('/')
def index():
animais = Animal.query.all()
return render_template('index.html', animais=animais)
# Duda - CADASTRAR
@app.route('/cadstrar', methods=['GET' ' POST'])
# 👤 DUDA — CADASTRAR
@app.route('/cadastrar', methods=['GET', 'POST'])
def cadastrar():
if request.method =='POST':
if request.method == 'POST':
novo = Animal(
nome=request.form['nome'],
especie=request.form['especie'],
idade=inte(request.form['idade']),
idade=int(request.form['idade']),
peso=float(request.form['peso'])
)
db.session.add(novo)
db.session.commit()
return redirect('/')
return
render_template('cadastrar.html')
return render_template('cadastrar.html')
# 👤 NICOLY — EDITAR
@app.route('/editar/<int:id>', methods=['GET', 'POST'])
def editar(id):
animal = Animal.query.get(id)
if request.method == 'POST':
animal.nome = request.form['nome']
animal.especie = request.form['especie']
animal.idade = int(request.form['idade'])
animal.peso = float(request.form['peso'])
db.session.commit()
return redirect('/')
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)
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