Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CRUD_Animais_da_Fazenda2
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
Hiago Rafael
CRUD_Animais_da_Fazenda2
Commits
4dda1a6d
Commit
4dda1a6d
authored
May 07, 2026
by
Hiago Rafael
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
po
parent
3bd092d4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
10 deletions
+35
-10
models.cpython-314.pyc
__pycache__/models.cpython-314.pyc
+0
-0
app.py
app.py
+35
-10
No files found.
__pycache__/models.cpython-314.pyc
View file @
4dda1a6d
No preview for this file type
app.py
View file @
4dda1a6d
from
flask
import
Flask
,
render_template
,
request
,
redirect
from
models
import
Animal
from
flask_sqlalchemy
import
SQLAlchemy
app
=
Flask
(
__name__
)
animais
=
[]
# CONFIGURAÇÃO DO BANCO
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///fazenda.db'
app
.
config
[
'SQLALCHEMY_TRACK_MODIFICATIONS'
]
=
False
db
=
SQLAlchemy
(
app
)
# TABELA
class
Animal
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
nome
=
db
.
Column
(
db
.
String
(
100
))
tipo
=
db
.
Column
(
db
.
String
(
100
))
idade
=
db
.
Column
(
db
.
Integer
)
# PÁGINA INICIAL
@app.route
(
'/'
)
def
index
():
animais
=
Animal
.
query
.
all
()
return
render_template
(
'index.html'
,
animais
=
animais
)
@app.route
(
'/cadastro'
)
def
cadastro
():
return
render_template
(
'cadastro.html'
)
# CADASTRAR
@app.route
(
'/adicionar'
,
methods
=
[
'POST'
])
def
adicionar
():
nome
=
request
.
form
[
'nome'
]
tipo
=
request
.
form
[
'tipo'
]
idade
=
request
.
form
[
'idade'
]
novo_animal
=
Animal
(
nome
,
tipo
,
idade
)
animais
.
append
(
novo_animal
)
novo_animal
=
Animal
(
nome
=
nome
,
tipo
=
tipo
,
idade
=
idade
)
db
.
session
.
add
(
novo_animal
)
db
.
session
.
commit
()
return
redirect
(
'/'
)
# EXCLUIR
@app.route
(
'/excluir/<int:id>'
)
def
excluir
(
id
):
if
0
<=
id
<
len
(
animais
):
animais
.
pop
(
id
)
animal
=
Animal
.
query
.
get
(
id
)
if
animal
:
db
.
session
.
delete
(
animal
)
db
.
session
.
commit
()
return
redirect
(
'/'
)
if
__name__
==
'__main__'
:
with
app
.
app_context
():
db
.
create_all
()
app
.
run
(
debug
=
True
)
\ 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