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
05e21a37
Commit
05e21a37
authored
Apr 16, 2026
by
Edvan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'main' of
http://gitlab.ariquemes.ifro.edu.br/2024105070069/CRUD_Animais_da_Fazenda
parents
f542cc3d
a9ee5c0d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
23 deletions
+30
-23
models.py
app.py/models.py
+26
-13
cadastro_pessoa.html
templates/cadastro_pessoa.html
+4
-10
No files found.
app.py/models.py
View file @
05e21a37
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
app
=
Flask
(
__name__
)
db
=
SQLAlchemy
()
class
Animal
(
db
.
Model
):
# Configuração do Banco de Dados SQLite
__tablename__
=
'animais'
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///database.db'
app
.
config
[
'SQLALCHEMY_TRACK_MODIFICATIONS'
]
=
False
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
# Inicializa o banco de dados no app
nome
=
db
.
Column
(
db
.
String
(
100
),
nullable
=
False
)
db
.
init_app
(
app
)
especie
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
)
idade
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
peso
=
db
.
Column
(
db
.
Float
,
nullable
=
False
)
def
__repr__
(
self
):
# COMANDO MÁGICO: Cria o banco de dados se ele não existir
return
f
'<Animal {self.nome}>'
with
app
.
app_context
():
\ No newline at end of file
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
templates/cadastro_pessoa.html
View file @
05e21a37
{% extends "base.html" %}
{% extends "base.html" %}
{% block content %}
{% block content %}
<h2>
Cadastro d
e Animal
</h2>
<h2>
Cadastro d
a Pessoa
</h2>
<form
method=
"POST"
>
<form
method=
"POST"
>
<label>
Nome do
Animal
:
</label><br>
<label>
Nome do
Pessoa
:
</label><br>
<input
type=
"text"
name=
"nome"
required
><br><br>
<input
type=
"text"
name=
"nome"
required
><br><br>
<label>
Espécie:
</label><br>
<input
type=
"text"
name=
"especie"
required
><br><br>
<label>
Raça:
</label><br>
<input
type=
"text"
name=
"raca"
><br><br>
<label>
Idade:
</label><br>
<label>
Idade:
</label><br>
<input
type=
"number"
name=
"idade"
><br><br>
<input
type=
"number"
name=
"idade"
><br><br>
...
@@ -25,8 +19,8 @@
...
@@ -25,8 +19,8 @@
<label>
Sexo:
</label><br>
<label>
Sexo:
</label><br>
<select
name=
"sexo"
>
<select
name=
"sexo"
>
<option
value=
"M"
>
Ma
ch
o
</option>
<option
value=
"M"
>
Ma
sculin
o
</option>
<option
value=
"F"
>
F
êmea
</option>
<option
value=
"F"
>
F
eminino
</option>
</select><br><br>
</select><br><br>
<button
type=
"submit"
>
Salvar
</button>
<button
type=
"submit"
>
Salvar
</button>
...
...
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