File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ from flask import Flask , request , render_template
5+
6+ app = Flask (__name__ )
7+
8+ @app .route ('/' , methods = ['GET' , 'POST' ])
9+ def home ():
10+ return render_template ('home.html' )
11+
12+ @app .route ('/signin' , methods = ['GET' ])
13+ def signin_form ():
14+ return render_template ('form.html' )
15+
16+ @app .route ('/signin' , methods = ['POST' ])
17+ def signin ():
18+ username = request .form ['username' ]
19+ password = request .form ['password' ]
20+ if username == 'admin' and password == 'password' :
21+ return render_template ('signin-ok.html' , username = username )
22+ return render_template ('form.html' , message = 'Bad username or password' , username = username )
23+
24+ if __name__ == '__main__' :
25+ app .run ()
Original file line number Diff line number Diff line change 1+ < html >
2+ < head >
3+ < title > Please Sign In</ title >
4+ </ head >
5+ < body >
6+ {% if message %}
7+ < p style ="color:red "> {{ message }}</ p >
8+ {% endif %}
9+ < form action ="/signin " method ="post ">
10+ < legend > Please sign in:</ legend >
11+ < p > < input name ="username " placeholder ="Username " value ="{{ username }} "> </ p >
12+ < p > < input name ="password " placeholder ="Password " type ="password "> </ p >
13+ < p > < button type ="submit "> Sign In</ button > </ p >
14+ </ form >
15+ </ body >
16+ </ html >
Original file line number Diff line number Diff line change 1+ < html >
2+ < head >
3+ < title > Home</ title >
4+ </ head >
5+ < body >
6+ < h1 style ="font-style:italic "> Home</ h1 >
7+ </ body >
8+ </ html >
Original file line number Diff line number Diff line change 1+ < html >
2+ < head >
3+ < title > Welcome, {{ username }}</ title >
4+ </ head >
5+ < body >
6+ < p > Welcome, {{ username }}!</ p >
7+ </ body >
8+ </ html >
You can’t perform that action at this time.
0 commit comments