-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
60 lines (49 loc) · 1.75 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from flask import Flask, render_template, request, url_for, redirect
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__, template_folder='templates')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///Bandas.sqlite3'
db = SQLAlchemy(app)
class Bandas(db.Model):
id = db.Column('id', db.Integer, primary_key=True, autoincrement=True)
nome = db.Column(db.String(150))
vertente = db.Column(db.String(150))
país = db.Column(db.String(150))
def __init__(self, nome, vertente, país):
self.nome = nome
self.vertente = vertente
self.país = país
#listando bandas
@app.route('/')
def Banda():
band = Bandas.query.all()
return render_template('bandas.html', banda=band)
#adcionando bandas ao BD
@app.route('/Add', methods=['GET', 'POST'])
def Add():
if request.method == 'POST':
band = Bandas(request.form['nome'], request.form['vertente'], request.form['país'])
db.session.add(band)
db.session.commit()
return redirect(url_for('Banda'))
return render_template('addband.html')
#atualizando informações das bandas
@app.route('/Update/<int:id>', methods=["GET", "POST"])
def Update(id):
band = Bandas.query.get(id)
if request.method == "POST":
band.nome = request.form['nome']
band.vertente = request.form['vertente']
band.país = request.form['país']
db.session.commit()
return redirect(url_for('Banda'))
return render_template('edit.html', banda=band)
#deletando bandas do BD
@app.route('/Del/<int:id>')
def Del(id):
band = Bandas.query.get(id)
db.session.delete(band)
db.session.commit()
return redirect(url_for('Banda'))
if __name__ == '__main__':
db.create_all()#criando BD
app.run(debug=True)