Commit 516ee663 by Hiago Rafael

ola

parent 206a8c20
<!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> <!DOCTYPE html>
<html lang="pt-br"> <html>
<head> <head>
<meta charset="UTF-8"> <title>Lista de Animais</title>
<title>CRUD Animais da Fazenda</title>
</head> </head>
<body> <body>
<h1>Cadastro de Animais</h1> <h1>Animais da Fazenda</h1>
<form action="/adicionar" method="POST"> <a href="/cadastro">➕ Novo Animal</a>
<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>
<hr> <ul>
{% for animal in animais %}
<h2>Animais cadastrados</h2> <li>
{{ animal.nome }} - {{ animal.especie }} - {{ animal.idade }} anos - {{ animal.peso }} kg
<ul> <a href="/excluir/{{ loop.index0 }}">❌ Excluir</a>
{% for animal in animais %} </li>
<li> {% endfor %}
{{ animal.nome }} - {{ animal.especie }} - {{ animal.idade }} anos - {{ animal.peso }} kg </ul>
<a href="/excluir/{{ loop.index0 }}">Excluir</a>
</li>
{% endfor %}
</ul>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -9,13 +9,18 @@ animais = [] ...@@ -9,13 +9,18 @@ animais = []
def index(): def index():
return render_template('index.html', animais=animais) return render_template('index.html', animais=animais)
@app.route('/cadastro')
def cadastro():
return render_template('cadastro.html')
@app.route('/adicionar', methods=['POST']) @app.route('/adicionar', methods=['POST'])
def adicionar(): def adicionar():
nome = request.form['nome'] nome = request.form['nome']
tipo = request.form['tipo'] especie = request.form['especie']
idade = request.form['idade'] 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) animais.append(novo_animal)
return redirect('/') return redirect('/')
......
class Animal: class Animal:
def __init__(self, nome, tipo, idade): def __init__(self, nome, especie, idade, peso):
self.nome = nome self.nome = nome
self.tipo = tipo self.especie = especie
self.idade = idade self.idade = idade
\ No newline at end of file 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