February 2018
Intermediate to advanced
456 pages
9h 56m
English
Our app can't be complete without the ability to log a user in! In our web_server.py, create a new class, LoginView:
class LoginView(MethodView):
def get(self):
if user_authenticated():
return redirect(url_for('home'))
else:
return render_template('login.html')
Like the get in our SignUpView, this one will check to see if the user is already authenticated. If so, then we will redirect them to the home endpoint, otherwise, we will render the login.html template.
At the end of our web_server.py module, add the following URL rule for the LoginView:
app.add_url_rule(
'/login', view_func=LoginView.as_view('login')
)
Any request to /login will now be directed to our LoginView.
Now create a new template, login.html , inside our ...
Read now
Unlock full access