Implement a flask app to look up a staff member's UID, given their name.
lecture2.py
file to staff_lookup_app.py
.
We can combine redirects and flashing to implement a login page in Flask, modeled after the example in the reading.
flaskStarter
directory to your account (outside public_html)
/user/fred
where fred is the person logged in. The page should also say that somewhere.You might do the login database like this:
passwds = {'fred': 'stinkbomb', 'george': 'butterbeer'}
Here's my solution. It's just 25 lines of code.
@app.route('/login/', methods=["GET", "POST"]) def login(): if request.method == 'GET': return render_template('login-form.html') # Dealing with POST passwds = {'fred': 'stinkbomb', 'george': 'butterbeer'} try: user = request.form['username'] passwd = request.form['password'] if passwds[user] == passwd: flash("You're logged in") return redirect( url_for('user', username=user )) else: flash("Sorry; incorrect") return render_template('login-form.html') except Exception as err: print 'Got this in /login/: ',err flash("Sorry, some kind of error occurred") return render_template('login-form.html') @app.route('/user/') def user(username): return render_template('userpage.html', username=username)