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
5
Issues
5
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
Ste
atividade_tres
Commits
187f62f4
You need to sign in or sign up before continuing.
Commit
187f62f4
authored
Apr 16, 2026
by
Ayram
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ayram
parent
d7b16b99
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
163 additions
and
23 deletions
+163
-23
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
+22
-7
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
db
.
create_all
()
from
flask
import
Flask
,
render_template
,
request
,
redirect
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()
class
Animal
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
nome
=
db
.
Column
(
db
.
String
(
100
))
especie
=
db
.
Column
(
db
.
String
(
100
))
idade
=
db
.
Column
(
db
.
Integer
)
peso
=
db
.
Column
(
db
.
Float
)
\ No newline at end of file
nome
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
)
especie
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
)
idade
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
peso
=
db
.
Column
(
db
.
Float
,
nullable
=
False
)
\ 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"
>
<input
type=
"text"
name=
"nome"
placeholder=
"Nome"
required
>
<input
type=
"text"
name=
"especie"
placeholder=
"Espécie"
required
>
<input
type=
"number"
name=
"idade"
min=
"0"
required
>
<input
type=
"number"
name=
"peso"
step=
"0.1"
min=
"0"
required
>
<button
type=
"submit"
>
Cadastrar
</button>
</form>
\ No newline at end of file
Nome:
<input
type=
"text"
name=
"nome"
required
><br>
Espécie:
<input
type=
"text"
name=
"especie"
required
><br>
Idade:
<input
type=
"number"
name=
"idade"
required
><br>
Peso:
<input
type=
"number"
step=
"0.1"
name=
"peso"
required
><br>
<button
type=
"submit"
>
Salvar
</button>
</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>
{% for animal in animais %}
<li>
{{ animal.nome }} | {{ animal.especie }} |
{{ animal.idade }} anos | {{ animal.peso }} kg
</li>
{% endfor %}
</ul>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>
Fazenda
</title>
</head>
<body>
<h1>
🐄 Animais da Fazenda
</h1>
<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