1+ from flask import Flask , render_template , url_for ,flash ,redirect
2+ from forms import RegistrationForm ,LoginForm
3+ app = Flask (__name__ )
4+
5+ app .config ['SECRET_KEY' ] = '08d9c1e388cbe976ae8e945842b94e14'
6+
7+
8+
9+ posts = [
10+ {
11+ 'author' : 'Aadit' ,
12+ 'title' : 'Blog Post 1' ,
13+ 'content' : 'Deep learning in toward data science' ,
14+ 'date_posted' : 'April 20, 2018'
15+ },
16+ {
17+ 'author' : 'Shukla' ,
18+ 'title' : 'Blog Post 2' ,
19+ 'content' : 'Balanced and Imbalanced Dataset' ,
20+ 'date_posted' : 'April 21, 2018'
21+ }
22+ ]
23+
24+
25+ @app .route ("/" )
26+ @app .route ("/home" )
27+ def home ():
28+ return render_template ('home.html' , posts = posts )
29+
30+
31+ @app .route ("/about" )
32+ def about ():
33+ return render_template ('about.html' , title = 'About' )
34+
35+
36+
37+ @app .route ("/register" , methods = ['GET' ,'POST' ])
38+ def register ():
39+ form = RegistrationForm ()
40+ if form .validate_on_submit ():
41+ flash (f'account created for{ form .Username .data } !' ,'Success' )
42+ return redirect (url_for ('home' ))
43+ return render_template ('register.html' ,title = 'Register' ,form = form )
44+
45+ @app .route ("/login" ,methods = ['GET' ,'POST' ])
46+ def login ():
47+ form = LoginForm ()
48+ if form .validate_on_submit ():
49+ if form .email .data == 'aaditshukla98710@gmail.com' and form .password .data == 'password' :
50+ flash ('you have been logined' ,'Success' )
51+ return redirect (url_for ('home' ))
52+ else :
53+ flash ('Unsuccessfully logined.please check username and password' ,'danger' )
54+
55+ return render_template ('login.html' ,title = 'login' ,form = form )
56+
57+
58+ if __name__ == '__main__' :
59+ app .run (debug = True )
0 commit comments