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
d3c5da65
Commit
d3c5da65
authored
Apr 16, 2026
by
bricioso
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
atualizei essa merda do banco denovo
parent
3e0e6b07
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
28 deletions
+34
-28
app.py
app.py/app.py
+24
-0
models.py
app.py/models.py
+10
-28
No files found.
app.py/app.py
0 → 100644
View file @
d3c5da65
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
from
models
import
db
,
Animal
app
=
Flask
(
__name__
)
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///database.db'
app
.
config
[
'SQLALCHEMY_TRACK_MODIFICATIONS'
]
=
False
db
.
init_app
(
app
)
with
app
.
app_context
():
db
.
create_all
()
# Isso cria o arquivo database.db pra você!
@app.route
(
'/'
)
def
index
():
animais
=
Animal
.
query
.
all
()
return
render_template
(
'lista.html'
,
animais
=
animais
)
@app.route
(
'/cadastro'
)
def
cadastro
():
return
render_template
(
'cadastro.html'
)
if
__name__
==
'__main__'
:
app
.
run
(
debug
=
True
)
\ No newline at end of file
app.py/models.py
View file @
d3c5da65
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
from
flask_sqlalchemy
import
SQLAlchemy
app
=
Flask
(
__name__
)
db
=
SQLAlchemy
(
)
# Configuração do Banco de Dados SQLite
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///database.db'
app
.
config
[
'SQLALCHEMY_TRACK_MODIFICATIONS'
]
=
False
# 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
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
)
\ 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