File tree 7 files changed +110
-0
lines changed 7 files changed +110
-0
lines changed Original file line number Diff line number Diff line change
1
+ from form import AgeForm
2
+ from form import legal_or_not
3
+ from flask import Flask
4
+ from flask import request
5
+ from flask import render_template
6
+
7
+
8
+ app = Flask (__name__ )
9
+
10
+
11
+ @app .route ('/form' , methods = ['GET' , 'POST' ])
12
+ def form_url ():
13
+ form = AgeForm (request .form )
14
+
15
+ if len (form .errors ):
16
+ print (form .errors )
17
+ if request .method == 'POST' :
18
+ return render_template ('success.html' ,
19
+ name = form .name .data ,
20
+ legal = legal_or_not (form .age .data ))
21
+ return render_template ('form.html' )
22
+
23
+
24
+ if __name__ == '__main__' :
25
+ app .run (debug = True , port = 5000 )
Original file line number Diff line number Diff line change
1
+ from wtforms import Form
2
+ from wtforms import StringField
3
+ from wtforms import IntegerField
4
+ from wtforms .validators import DataRequired
5
+
6
+
7
+ class AgeForm (Form ):
8
+ name = StringField ('name' , validators = [DataRequired ()])
9
+ age = IntegerField ('age' , validators = [DataRequired ()])
10
+
11
+
12
+ def legal_or_not (age ):
13
+ return (age >= 18 )
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html lang ="en ">
3
+ < head >
4
+ <!-- Required meta tags -->
5
+ < meta charset ="utf-8 ">
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1, shrink-to-fit=no ">
7
+
8
+ <!-- Bootstrap CSS -->
9
+ < link rel ="stylesheet " href ="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css " integrity ="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T " crossorigin ="anonymous ">
10
+
11
+ < title > Hello, world!</ title >
12
+ </ head >
13
+ < body >
14
+ < div class ="container ">
15
+ < div class ="row justify-content-md-center ">
16
+ < div class ="col-md-auto text-center ">
17
+ < h1 class ="mt-5 "> Formulario para edad:</ h1 >
18
+ < form action ="" method ="post " role ="form ">
19
+ < div class ="form-group ">
20
+ < br >
21
+ < label for ="name "> Nombre:</ label >
22
+ < input type ="text " class ="form-control " id ="name " name ="name " placeholder ="Nombre ">
23
+ < br >
24
+ < label for ="age "> Edad:</ label >
25
+ < input type ="text " class ="form-control " id ="age " name ="age " placeholder ="Edad ">
26
+ </ div >
27
+ < button type ="submit " class ="btn btn-info "> Registrar edad</ button >
28
+ </ form >
29
+ < br > < br > < br >
30
+ </ div >
31
+ </ div >
32
+ </ div >
33
+
34
+ <!-- Optional JavaScript -->
35
+ <!-- jQuery first, then Popper.js, then Bootstrap JS -->
36
+ < script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js " integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo " crossorigin ="anonymous "> </ script >
37
+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js " integrity ="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1 " crossorigin ="anonymous "> </ script >
38
+ < script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js " integrity ="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM " crossorigin ="anonymous "> </ script >
39
+ </ body >
40
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html lang ="en ">
3
+ < head >
4
+ <!-- Required meta tags -->
5
+ < meta charset ="utf-8 ">
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1, shrink-to-fit=no ">
7
+
8
+ <!-- Bootstrap CSS -->
9
+ < link rel ="stylesheet " href ="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css " integrity ="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T " crossorigin ="anonymous ">
10
+
11
+ < title > Hello, world!</ title >
12
+ </ head >
13
+ < body >
14
+ < div class ="jumbotron jumbotron-fluid ">
15
+ < div class ="container ">
16
+ < h1 class ="display-4 "> ¡Hola, {{ name }}!</ h1 >
17
+ {% if legal %}
18
+ < p class ="lead "> Te informamos que puedes formar parte del club de la mayoría de edad.</ p >
19
+ {% else %}
20
+ < p class ="lead "> Desafortunadamente aún te falta, es decir, estás chav@.</ p >
21
+ {% endif %}
22
+ </ div >
23
+ </ div >
24
+
25
+ <!-- Optional JavaScript -->
26
+ <!-- jQuery first, then Popper.js, then Bootstrap JS -->
27
+ < script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js " integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo " crossorigin ="anonymous "> </ script >
28
+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js " integrity ="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1 " crossorigin ="anonymous "> </ script >
29
+ < script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js " integrity ="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM " crossorigin ="anonymous "> </ script >
30
+ </ body >
31
+ </ html >
Original file line number Diff line number Diff line change 1
1
flask
2
+ wtforms
2
3
gunicorn
You can’t perform that action at this time.
0 commit comments