Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CRUD_Animais_da_Fazenda
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafaela Ramos
CRUD_Animais_da_Fazenda
Commits
9a312db5
Commit
9a312db5
authored
Apr 16, 2026
by
Marina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cvsgdfd
parent
ea3ff480
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
20 deletions
+73
-20
models.cpython-314.pyc
__pycache__/models.cpython-314.pyc
+0
-0
app.py
app.py
+36
-11
animais.db
instance/animais.db
+0
-0
base.html
templates/base.html
+23
-0
cadastro.html
templates/cadastro.html
+4
-4
editar.html
templates/editar.html
+4
-4
index.html
templates/index.html
+6
-1
No files found.
__pycache__/models.cpython-314.pyc
0 → 100644
View file @
9a312db5
File added
app.py
View file @
9a312db5
from
flask
import
Flask
,
render_template
,
request
,
redirect
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
from
models
import
db
,
Animal
from
models
import
db
,
Animal
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
...
@@ -9,11 +9,11 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
...
@@ -9,11 +9,11 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db
.
init_app
(
app
)
db
.
init_app
(
app
)
# Criar banco
# Criar banco
de dados
with
app
.
app_context
():
with
app
.
app_context
():
db
.
create_all
()
db
.
create_all
()
#
LISTAR
#
ROTA PRINCIPAL (LISTAR)
@app.route
(
'/'
)
@app.route
(
'/'
)
def
index
():
def
index
():
animais
=
Animal
.
query
.
all
()
animais
=
Animal
.
query
.
all
()
...
@@ -23,16 +23,26 @@ def index():
...
@@ -23,16 +23,26 @@ def index():
@app.route
(
'/cadastrar'
,
methods
=
[
'GET'
,
'POST'
])
@app.route
(
'/cadastrar'
,
methods
=
[
'GET'
,
'POST'
])
def
cadastrar
():
def
cadastrar
():
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
try
:
nome
=
request
.
form
[
'nome'
]
nome
=
request
.
form
[
'nome'
]
especie
=
request
.
form
[
'especie'
]
especie
=
request
.
form
[
'especie'
]
idade
=
request
.
form
[
'idade'
]
idade
=
request
.
form
.
get
(
'idade'
)
peso
=
request
.
form
[
'peso'
]
peso
=
request
.
form
.
get
(
'peso'
)
novo
=
Animal
(
nome
=
nome
,
especie
=
especie
,
idade
=
int
(
idade
)
if
idade
else
None
,
peso
=
float
(
peso
)
if
peso
else
None
)
novo
=
Animal
(
nome
=
nome
,
especie
=
especie
,
idade
=
idade
,
peso
=
peso
)
db
.
session
.
add
(
novo
)
db
.
session
.
add
(
novo
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
redirect
(
'/'
)
return
redirect
(
url_for
(
'index'
))
except
Exception
as
e
:
return
f
"Erro ao cadastrar: {e}"
return
render_template
(
'cadastrar.html'
)
return
render_template
(
'cadastrar.html'
)
...
@@ -42,23 +52,37 @@ def editar(id):
...
@@ -42,23 +52,37 @@ def editar(id):
animal
=
Animal
.
query
.
get_or_404
(
id
)
animal
=
Animal
.
query
.
get_or_404
(
id
)
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
try
:
animal
.
nome
=
request
.
form
[
'nome'
]
animal
.
nome
=
request
.
form
[
'nome'
]
animal
.
especie
=
request
.
form
[
'especie'
]
animal
.
especie
=
request
.
form
[
'especie'
]
animal
.
idade
=
request
.
form
[
'idade'
]
animal
.
peso
=
request
.
form
[
'peso'
]
idade
=
request
.
form
.
get
(
'idade'
)
peso
=
request
.
form
.
get
(
'peso'
)
animal
.
idade
=
int
(
idade
)
if
idade
else
None
animal
.
peso
=
float
(
peso
)
if
peso
else
None
db
.
session
.
commit
()
db
.
session
.
commit
()
return
redirect
(
'/'
)
return
redirect
(
url_for
(
'index'
))
except
Exception
as
e
:
return
f
"Erro ao editar: {e}"
return
render_template
(
'editar.html'
,
animal
=
animal
)
return
render_template
(
'editar.html'
,
animal
=
animal
)
# EXCLUIR
# EXCLUIR
@app.route
(
'/excluir/<int:id>'
)
@app.route
(
'/excluir/<int:id>'
)
def
excluir
(
id
):
def
excluir
(
id
):
try
:
animal
=
Animal
.
query
.
get_or_404
(
id
)
animal
=
Animal
.
query
.
get_or_404
(
id
)
db
.
session
.
delete
(
animal
)
db
.
session
.
delete
(
animal
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
redirect
(
'/'
)
return
redirect
(
url_for
(
'index'
))
except
Exception
as
e
:
return
f
"Erro ao excluir: {e}"
# EXECUTAR
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
.
run
(
debug
=
True
)
app
.
run
(
debug
=
True
)
\ No newline at end of file
instance/animais.db
0 → 100644
View file @
9a312db5
File added
templates/base.html
View file @
9a312db5
<!DOCTYPE html>
<html>
<head>
<title>
Sistema da Fazenda
</title>
<link
rel=
"stylesheet"
href=
"{{ url_for('static', filename='style.css') }}"
>
</head>
<body>
<h1>
🐄 Sistema da Fazenda
</h1>
<nav>
<a
href=
"/"
>
Início
</a>
|
<a
href=
"/cadastrar"
>
Cadastrar Animal
</a>
</nav>
<hr>
<!-- ESSENCIAL: sem isso nada aparece -->
{% block content %}{% endblock %}
</body>
</html>
\ No newline at end of file
templates/cadastro.html
View file @
9a312db5
...
@@ -5,10 +5,10 @@
...
@@ -5,10 +5,10 @@
<h2>
Cadastrar Animal
</h2>
<h2>
Cadastrar Animal
</h2>
<form
method=
"POST"
>
<form
method=
"POST"
>
<input
type=
"text"
name=
"nome"
placeholder=
"Nome"
required
><br>
<input
type=
"text"
name=
"nome"
placeholder=
"Nome"
required
><br>
<br>
<input
type=
"text"
name=
"especie"
placeholder=
"Espécie"
required
><br>
<input
type=
"text"
name=
"especie"
placeholder=
"Espécie"
required
><br>
<br>
<input
type=
"number"
name=
"idade"
placeholder=
"Idade"
><br>
<input
type=
"number"
name=
"idade"
placeholder=
"Idade"
><br>
<br>
<input
type=
"number"
step=
"0.1"
name=
"peso"
placeholder=
"Peso"
><br>
<input
type=
"number"
step=
"0.1"
name=
"peso"
placeholder=
"Peso"
><br>
<br>
<button
type=
"submit"
>
Salvar
</button>
<button
type=
"submit"
>
Salvar
</button>
</form>
</form>
...
...
templates/editar.html
View file @
9a312db5
...
@@ -5,10 +5,10 @@
...
@@ -5,10 +5,10 @@
<h2>
Editar Animal
</h2>
<h2>
Editar Animal
</h2>
<form
method=
"POST"
>
<form
method=
"POST"
>
<input
type=
"text"
name=
"nome"
value=
"{{ animal.nome }}"
required
><br>
<input
type=
"text"
name=
"nome"
value=
"{{ animal.nome }}"
required
><br>
<br>
<input
type=
"text"
name=
"especie"
value=
"{{ animal.especie }}"
required
><br>
<input
type=
"text"
name=
"especie"
value=
"{{ animal.especie }}"
required
><br>
<br>
<input
type=
"number"
name=
"idade"
value=
"{{ animal.idade }}"
><br>
<input
type=
"number"
name=
"idade"
value=
"{{ animal.idade }}"
><br>
<br>
<input
type=
"number"
step=
"0.1"
name=
"peso"
value=
"{{ animal.peso }}"
><br>
<input
type=
"number"
step=
"0.1"
name=
"peso"
value=
"{{ animal.peso }}"
><br>
<br>
<button
type=
"submit"
>
Atualizar
</button>
<button
type=
"submit"
>
Atualizar
</button>
</form>
</form>
...
...
templates/index.html
View file @
9a312db5
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
<h2>
Lista de Animais
</h2>
<h2>
Lista de Animais
</h2>
{% if animais %}
<table>
<table>
<tr>
<tr>
<th>
Nome
</th>
<th>
Nome
</th>
...
@@ -25,7 +26,10 @@
...
@@ -25,7 +26,10 @@
</td>
</td>
</tr>
</tr>
{% endfor %}
{% endfor %}
</table>
</table>
{% else %}
<p>
🚜 Nenhum animal cadastrado ainda.
</p>
{% endif %}
{% endblock %}
{% endblock %}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment