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
7
Issues
7
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_Fazenda
Commits
3e0e6b07
Commit
3e0e6b07
authored
Apr 16, 2026
by
bricioso
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
atualizei o banco de dados em teste
parent
b4edfba9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
14 deletions
+27
-14
models.py
app.py/models.py
+27
-14
No files found.
app.py/models.py
View file @
3e0e6b07
from
flask_sqlalchemy
import
SQLAlchemy
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
from
models
import
db
,
Animal
# Importa a configuração do banco e a classe Animal
# Inicializa o banco de dados
db
=
SQLAlchemy
()
app
=
Flask
(
__name__
)
class
Animal
(
db
.
Model
):
__tablename__
=
'animais'
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
nome
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
)
especie
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
)
idade
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
peso
=
db
.
Column
(
db
.
Float
,
nullable
=
False
)
# Configuração do Banco de Dados SQLite
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///database.db'
app
.
config
[
'SQLALCHEMY_TRACK_MODIFICATIONS'
]
=
False
def
__repr__
(
self
):
return
f
'<Animal {self.nome}>'
\ No newline at end of file
# Inicializa o banco de dados no app
db
.
init_app
(
app
)
# COMANDO MÁGICO: Cria o banco de dados se ele não existir
with
app
.
app_context
():
db
.
create_all
()
@app.route
(
'/'
)
def
index
():
# Busca todos os animais do banco para exibir na lista
animais
=
Animal
.
query
.
all
()
return
render_template
(
'lista.html'
,
animais
=
animais
)
# Rota para abrir o formulário de cadastro
@app.route
(
'/cadastro'
)
def
cadastro
():
return
render_template
(
'cadastro.html'
)
if
__name__
==
'__main__'
:
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