Commit a2ee6857 by Edvan
parents 6b04c397 14ac72de
<!DOCTYPE html>
<html>
<head>
<title>Cadastro</title>
</head>
<body>
<h1>Cadastrar Animal</h1>
<form action="/adicionar" method="POST">
<input type="text" name="nome" placeholder="Nome" required><br><br>
<input type="text" name="especie" placeholder="Espécie" required><br><br>
<input type="number" name="idade" placeholder="Idade" required><br><br>
<input type="number" step="0.1" name="peso" placeholder="Peso (kg)" required><br><br>
<button type="submit">Salvar</button>
</form>
<br>
<a href="/">⬅ Voltar</a>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="pt-br">
<html>
<head>
<meta charset="UTF-8">
<title>CRUD Animais da Fazenda</title>
<title>Lista de Animais</title>
</head>
<body>
<h1>Cadastro de Animais</h1>
<h1>Animais da Fazenda</h1>
<form action="/adicionar" method="POST">
<input type="text" name="nome" placeholder="Nome" required>
<input type="text" name="especie" placeholder="Espécie" required>
<input type="number" name="idade" placeholder="Idade" required>
<input type="number" step="0.1" name="peso" placeholder="Peso (kg)" required>
<button type="submit">Adicionar</button>
</form>
<a href="/cadastro">➕ Novo Animal</a>
<hr>
<h2>Animais cadastrados</h2>
<ul>
<ul>
{% for animal in animais %}
<li>
{{ animal.nome }} - {{ animal.especie }} - {{ animal.idade }} anos - {{ animal.peso }} kg
<a href="/excluir/{{ loop.index0 }}">Excluir</a>
<a href="/excluir/{{ loop.index0 }}">Excluir</a>
</li>
{% endfor %}
</ul>
</ul>
</body>
</html>
\ No newline at end of file
......@@ -9,13 +9,18 @@ animais = []
def index():
return render_template('index.html', animais=animais)
@app.route('/cadastro')
def cadastro():
return render_template('cadastro.html')
@app.route('/adicionar', methods=['POST'])
def adicionar():
nome = request.form['nome']
tipo = request.form['tipo']
especie = request.form['especie']
idade = request.form['idade']
peso = request.form['peso']
novo_animal = Animal(nome, tipo, idade)
novo_animal = Animal(nome, especie, idade, peso)
animais.append(novo_animal)
return redirect('/')
......
class Animal:
def __init__(self, nome, tipo, idade):
def __init__(self, nome, especie, idade, peso):
self.nome = nome
self.tipo = tipo
self.especie = especie
self.idade = idade
self.peso = peso
\ 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