File tree 3 files changed +109
-0
lines changed
3 files changed +109
-0
lines changed Original file line number Diff line number Diff line change
1
+ from flask import Flask
2
+ from flask import render_template
3
+ from flask import request , redirect
4
+ from flask import g
5
+ import sqlite3
6
+
7
+ app = Flask (__name__ )
8
+
9
+ @app .before_request
10
+ def before_request ():
11
+ g .db = sqlite3 .connect ("emails.db" )
12
+
13
+ @app .teardown_request
14
+ def teardown_request (exception ):
15
+ if hasattr (g , 'db' ):
16
+ g .db .close ()
17
+
18
+ @app .route ('/' )
19
+ def hello_world ():
20
+ return render_template ('index.html' )
21
+
22
+ @app .route ('/signup.html' , methods = ['POST' ])
23
+ def signup ():
24
+ email = request .form ['email' ]
25
+ g .db .execute ("INSERT INTO email_addresses VALUES (?)" , [email ])
26
+ g .db .commit ()
27
+ return redirect ('/' )
28
+
29
+ @app .route ('/emails.html' )
30
+ def emails ():
31
+ email_addresses = g .db .execute ("SELECT email FROM email_addresses" ).fetchall ()
32
+ return render_template ('emails.html' , email_addresses = email_addresses )
33
+
34
+ if __name__ == '__main__' :
35
+ app .run (debug = True )
Original file line number Diff line number Diff line change
1
+ < html >
2
+ < head >
3
+ < title > Cats Everywhere email addresses</ title >
4
+ </ head >
5
+ < body >
6
+ < p > Here are all the emails we have collected:</ p >
7
+ < ul >
8
+ {% for email in email_addresses %}
9
+ < li > {{ email }}</ li >
10
+ {% endfor %}
11
+ </ ul >
12
+ < p > THIS IS GONNA ROCK!</ p >
13
+ </ body >
14
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > Cats Everywhere!</ title >
6
+
7
+ < link href ='http://fonts.googleapis.com/css?family=Sintony:400,700 ' rel ='stylesheet ' type ='text/css '>
8
+
9
+ < style type ="text/css ">
10
+ body
11
+ {
12
+ background-color : # 000 ;
13
+ }
14
+
15
+ h1
16
+ {
17
+ font-size : 48px ;
18
+ margin-top : 0 ;
19
+ font-family : Arial, sans-serif;
20
+ text-shadow : 2px 0 15px # 292929 ;
21
+ letter-spacing : 4px ;
22
+ text-decoration : none;
23
+ color : # DDD ;
24
+ }
25
+
26
+ # banner
27
+ {
28
+ width : 500px ;
29
+ height : 200px ;
30
+ text-align : center;
31
+ background-image : url (http://i.imgur.com/MQHYB.jpg);
32
+ background-repeat : no-repeat;
33
+ border-radius : 5px ;
34
+ margin : 90px auto auto;
35
+ padding : 80px 0 ;
36
+ }
37
+
38
+ .lead
39
+ {
40
+ background-color : rgba (255 , 255 , 255 , 0.6 );
41
+ border-radius : 3px ;
42
+ box-shadow : rgba (0 , 0 , 0 , 0.2 ) 0 1px 3px ;
43
+ font-family : Sintony, sans-serif;
44
+ }
45
+ </ style >
46
+
47
+ </ head >
48
+
49
+ < body >
50
+ < div id ="banner ">
51
+ < h1 > cats everywhere</ h1 >
52
+ < p class ="lead "> We're bringing cats to the internet. Free. Cute. Awesome.</ p >
53
+ < form action ="signup.html " method ="post ">
54
+ < input type ="text " name ="email "> </ input >
55
+ < input type ="submit " value ="Signup "> </ input >
56
+ </ form >
57
+ </ div >
58
+
59
+ </ body >
60
+ </ html >
You can’t perform that action at this time.
0 commit comments