Meu Primeiro Commit

parents
from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
import os
app = Flask(__name__)
# Caminho do banco de dados
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'database.db')
db = SQLAlchemy(app)
# Modelo da Tabela
class Pessoa(db.Model):
id = db.Column(db.Integer, primary_key=True)
nome = db.Column(db.String(100))
sexo = db.Column(db.String(20))
data_nascimento = db.Column(db.String(20))
cidade = db.Column(db.String(100))
telefone = db.Column(db.String(11))
@app.route('/')
def index():
pessoas = Pessoa.query.all()
return render_template('index.html', pessoas=pessoas)
@app.route('/cadastro', methods=['GET', 'POST'])
def cadastro():
if request.method == 'POST':
nova = Pessoa(
nome=request.form['nome'],
sexo=request.form['sexo'],
data_nascimento=request.form['data_nascimento'],
cidade=request.form['cidade'],
telefone=request.form['telefone']
)
db.session.add(nova)
db.session.commit()
return redirect(url_for('index'))
return render_template('cadastro.html')
if __name__ == '__main__':
with app.app_context():
db.create_all()
app.run(debug=True)
\ No newline at end of file
File added
blinker==1.9.0
click==8.3.1
colorama==0.4.6
Flask==3.1.3
Flask-SQLAlchemy==3.1.1
greenlet==3.3.2
itsdangerous==2.2.0
Jinja2==3.1.6
MarkupSafe==3.0.3
SQLAlchemy==2.0.48
typing_extensions==4.15.0
Werkzeug==3.1.7
html{
background-color: #9fcbf1;
font-family: "Lexend", sans-serif;
font-optical-sizing: auto;
font-weight: 100;
font-style: normal;
margin-top: 50px;
}
table{
background-color: white;
margin-top: 10px;
border-radius: 15px;
padding: 10px;
margin: 0 auto;
}
td{
font-weight: 200;
padding: 5px;
border-radius: 7px;
}
th{
border-radius: 7px;
}
body {
text-align: center;
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='style/index.css') }}">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&display=swap" rel="stylesheet">
<title>Cadastro</title>
</head>
<body>
<h1>Nova Pessoa</h1>
<form method="POST">
Nome: <input type="text" name="nome" required><br>
Sexo: <select name="sexo">
<option>Masculino</option>
<option>Feminino</option>
</select><br>
Nascimento: <input type="date" name="data_nascimento" required><br>
Cidade: <input type="text" name="cidade" required><br>
Telefone: <input type="number" name="telefone" required><br>
<button type="submit">Salvar</button>
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='style/index.css') }}">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&display=swap" rel="stylesheet">
<title>Lista de Pessoas</title>
</head>
<body>
<h1>Pessoas Cadastradas</h1>
<a href="/cadastro"><button>Novo Cadastro</button></a>
<table border="1">
<tr>
<th>Nome</th>
<th>Sexo</th>
<th>Data</th>
<th>Cidade</th>
<th>Telefone</th>
</tr>
{% for p in pessoas %}
<tr>
<td>{{ p.nome }}</td>
<td>{{ p.sexo }}</td>
<td>{{ p.data_nascimento }}</td>
<td>{{ p.cidade }}</td>
<td>{{ p.telefone }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment