-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
67 lines (51 loc) · 1.63 KB
/
app.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
61
62
63
64
65
66
67
from dbutils import MONGO_URI
from dbutils import db_connect
from dbutils import db_insert_user
from dbutils import db_find_all
from form import EmailForm
from form import LoginForm
from flask import Flask
from flask import request
from flask import render_template
app = Flask(__name__)
#CCreating collections called users
users = db_connect(MONGO_URI,"mi_app",'users')
#@app.route('/tables')
#def tables():
# return render_template('tables.html')
@app.route('/', methods=['GET', 'POST'])
def index():
form = EmailForm(request.form)
flag = False
name = None
if len(form.errors):
print(form.errors)
if request.method == 'POST':
email = form.email.data
name = form.name.data
if email != '' and name != '':
print(f"Nombre capturado: {name}")
print(f"Email capturado: {email}")
user = {
"name": name,
"email": email
}
flag = True
return render_template('index.html', flag=flag, name=name)
@app.route('/admin', methods=['GET', 'POST'])
def login():
form = LoginForm(request.form)
login_error = False
if len(form.errors):
print(form.errors)
if request.method == 'POST':
if form.username.data == 'admin' and form.password.data == 'admin':
return render_template('tables.html')
else:
login_error = True
return render_template('login.html', login_error=login_error)
@app.errorhandler(404)
def no_encontrado(error=None):
return render_template("404.html", url=request.url)
if __name__ == '__main__':
app.run(debug=True, port=5000)