Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atividade_tres
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
0
Merge Requests
0
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
Ayram
atividade_tres
Commits
187f62f4
Commit
187f62f4
authored
Apr 16, 2026
by
Ayram
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ayram
parent
d7b16b99
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
162 additions
and
21 deletions
+162
-21
models.cpython-314.pyc
__pycache__/models.cpython-314.pyc
+0
-0
app.py
app.py
+66
-2
models.py
models.py
+5
-5
cadastro.html
templates/cadastro.html
+21
-5
editar.html
templates/editar.html
+23
-0
index.html
templates/index.html
+28
-9
sobre.html
templates/sobre.html
+19
-0
No files found.
__pycache__/models.cpython-314.pyc
View file @
187f62f4
No preview for this file type
app.py
View file @
187f62f4
from
models
import
db
from
flask
import
Flask
,
render_template
,
request
,
redirect
db
.
create_all
()
from
models
import
db
,
Animal
app
=
Flask
(
__name__
)
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///animais.db'
app
.
config
[
'SQLALCHEMY_TRACK_MODIFICATIONS'
]
=
False
db
.
init_app
(
app
)
# Criar banco
with
app
.
app_context
():
db
.
create_all
()
# Página principal (LISTAR)
@app.route
(
'/'
)
def
index
():
animais
=
Animal
.
query
.
all
()
return
render_template
(
'index.html'
,
animais
=
animais
)
# CADASTRO
@app.route
(
'/cadastro'
,
methods
=
[
'GET'
,
'POST'
])
def
cadastro
():
if
request
.
method
==
'POST'
:
novo
=
Animal
(
nome
=
request
.
form
[
'nome'
],
especie
=
request
.
form
[
'especie'
],
idade
=
request
.
form
[
'idade'
],
peso
=
request
.
form
[
'peso'
]
)
db
.
session
.
add
(
novo
)
db
.
session
.
commit
()
return
redirect
(
'/'
)
return
render_template
(
'cadastro.html'
)
# EDITAR
@app.route
(
'/editar/<int:id>'
,
methods
=
[
'GET'
,
'POST'
])
def
editar
(
id
):
animal
=
Animal
.
query
.
get_or_404
(
id
)
if
request
.
method
==
'POST'
:
animal
.
nome
=
request
.
form
[
'nome'
]
animal
.
especie
=
request
.
form
[
'especie'
]
animal
.
idade
=
request
.
form
[
'idade'
]
animal
.
peso
=
request
.
form
[
'peso'
]
db
.
session
.
commit
()
return
redirect
(
'/'
)
return
render_template
(
'editar.html'
,
animal
=
animal
)
# EXCLUIR
@app.route
(
'/excluir/<int:id>'
)
def
excluir
(
id
):
animal
=
Animal
.
query
.
get_or_404
(
id
)
db
.
session
.
delete
(
animal
)
db
.
session
.
commit
()
return
redirect
(
'/'
)
# SOBRE
@app.route
(
'/sobre'
)
def
sobre
():
return
render_template
(
'sobre.html'
)
if
__name__
==
'__main__'
:
app
.
run
(
debug
=
True
)
\ No newline at end of file
models.py
View file @
187f62f4
...
@@ -4,7 +4,7 @@ db = SQLAlchemy()
...
@@ -4,7 +4,7 @@ db = SQLAlchemy()
class
Animal
(
db
.
Model
):
class
Animal
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
nome
=
db
.
Column
(
db
.
String
(
100
))
nome
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
)
especie
=
db
.
Column
(
db
.
String
(
100
))
especie
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
)
idade
=
db
.
Column
(
db
.
Integer
)
idade
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
peso
=
db
.
Column
(
db
.
Float
)
peso
=
db
.
Column
(
db
.
Float
,
nullable
=
False
)
\ No newline at end of file
\ No newline at end of file
templates/cadastro.html
View file @
187f62f4
<!DOCTYPE html>
<html>
<head>
<title>
Cadastro
</title>
</head>
<body>
<h1>
Cadastrar Animal
</h1>
<form
method=
"POST"
>
<form
method=
"POST"
>
<input
type=
"text"
name=
"nome"
placeholder=
"Nome"
required
>
Nome:
<input
type=
"text"
name=
"nome"
required
><br>
<input
type=
"text"
name=
"especie"
placeholder=
"Espécie"
required
>
Espécie:
<input
type=
"text"
name=
"especie"
required
><br>
<input
type=
"number"
name=
"idade"
min=
"0"
required
>
Idade:
<input
type=
"number"
name=
"idade"
required
><br>
<input
type=
"number"
name=
"peso"
step=
"0.1"
min=
"0"
required
>
Peso:
<input
type=
"number"
step=
"0.1"
name=
"peso"
required
><br>
<button
type=
"submit"
>
Cadastrar
</button>
<button
type=
"submit"
>
Salvar
</button>
</form>
</form>
<a
href=
"/"
>
Voltar
</a>
</body>
</html>
\ No newline at end of file
templates/editar.html
0 → 100644
View file @
187f62f4
<!DOCTYPE html>
<html>
<head>
<title>
Editar
</title>
</head>
<body>
<h1>
Editar Animal
</h1>
<form
method=
"POST"
>
Nome:
<input
type=
"text"
name=
"nome"
value=
"{{ animal.nome }}"
required
><br>
Espécie:
<input
type=
"text"
name=
"especie"
value=
"{{ animal.especie }}"
required
><br>
Idade:
<input
type=
"number"
name=
"idade"
value=
"{{ animal.idade }}"
required
><br>
Peso:
<input
type=
"number"
step=
"0.1"
name=
"peso"
value=
"{{ animal.peso }}"
required
><br>
<button
type=
"submit"
>
Atualizar
</button>
</form>
<a
href=
"/"
>
Voltar
</a>
</body>
</html>
\ No newline at end of file
templates/index.html
View file @
187f62f4
<ul>
<!DOCTYPE html>
{% for animal in animais %}
<html>
<li>
<head>
{{ animal.nome }} | {{ animal.especie }} |
<title>
Fazenda
</title>
{{ animal.idade }} anos | {{ animal.peso }} kg
</head>
</li>
<body>
{% endfor %}
</ul>
<h1>
🐄 Animais da Fazenda
</h1>
\ No newline at end of file
<a
href=
"/cadastro"
>
Cadastrar
</a>
|
<a
href=
"/sobre"
>
Sobre
</a>
<hr>
{% for animal in animais %}
<p>
<b>
{{ animal.nome }}
</b>
({{ animal.especie }}) |
Idade: {{ animal.idade }} |
Peso: {{ animal.peso }} kg
<a
href=
"/editar/{{ animal.id }}"
>
Editar
</a>
<a
href=
"/excluir/{{ animal.id }}"
>
Excluir
</a>
</p>
{% endfor %}
</body>
</html>
\ No newline at end of file
templates/sobre.html
View file @
187f62f4
<!DOCTYPE html>
<html>
<head>
<title>
Sobre
</title>
</head>
<body>
<h1>
Sobre o Projeto
</h1>
<p>
Sistema CRUD para gerenciamento de animais de uma fazenda.
Permite cadastrar, listar, editar e excluir animais.
</p>
<a
href=
"/"
>
Voltar
</a>
</body>
</html>
\ 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