-
Notifications
You must be signed in to change notification settings - Fork 800
/
Copy pathapp.py
30 lines (24 loc) · 904 Bytes
/
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
# import the Flask class from the flask module
from flask import Flask, render_template, redirect, url_for, request
# create the application object
app = Flask(__name__)
# use decorators to link the function to a url
@app.route('/')
def home():
return "Hello, World!" # return a string
@app.route('/welcome')
def welcome():
return render_template('welcome.html') # render a template
# route for handling the login page logic
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != 'admin' or request.form['password'] != 'admin':
error = 'Invalid Credentials. Please try again.'
else:
return redirect(url_for('home'))
return render_template('login.html', error=error)
# start the server with the 'run()' method
if __name__ == '__main__':
app.run(debug=True)