Commit c0022fa7 by 2024105070020

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
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'database.db')
db = SQLAlchemy(app)
# Tabela do EmpregaMais
class Curriculo(db.Model):
id = db.Column(db.Integer, primary_key=True)
nome = db.Column(db.String(100))
email = db.Column(db.String(100))
telefone = db.Column(db.String(20))
cidade = db.Column(db.String(100))
experiencia = db.Column(db.String(200))
@app.route('/')
def index():
curriculos = Curriculo.query.all()
return render_template('index.html', curriculos=curriculos)
@app.route('/cadastro', methods=['GET', 'POST'])
def cadastro():
if request.method == 'POST':
novo = Curriculo(
nome=request.form['nome'],
email=request.form['email'],
telefone=request.form['telefone'],
cidade=request.form['cidade'],
experiencia=request.form['experiencia']
)
db.session.add(novo)
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
<!DOCTYPE html>
<html>
<head>
<title>Cadastro</title>
</head>
<body>
<h1>Novo Currículo</h1>
<form method="POST">
Nome:
<input type="text" name="nome" required>
<br><br>
Email:
<input type="email" name="email" required>
<br><br>
Telefone:
<input type="text" name="telefone" required>
<br><br>
Cidade:
<input type="text" name="cidade" required>
<br><br>
Experiência:
<input type="text" name="experiencia" required>
<br><br>
<button type="submit">
Salvar
</button>
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>EmpregaMais</title>
</head>
<body>
<h1>Currículos Cadastrados</h1>
<a href="/cadastro">
<button>Novo Currículo</button>
</a>
<table border="1" style="margin-top:10px">
<tr>
<th>Nome</th>
<th>Email</th>
<th>Telefone</th>
<th>Cidade</th>
<th>Experiência</th>
</tr>
{% for c in curriculos %}
<tr>
<td>{{ c.nome }}</td>
<td>{{ c.email }}</td>
<td>{{ c.telefone }}</td>
<td>{{ c.cidade }}</td>
<td>{{ c.experiencia }}</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