Working Example

This commit is contained in:
Rich
2021-07-03 19:40:40 +01:00
parent d50fbde5de
commit c357c654a6
16 changed files with 416 additions and 23 deletions

View File

@@ -1,10 +1,19 @@
from flask import render_template, flash, redirect, url_for
from flask import flash, redirect, render_template, url_for
from flask_login import current_user, login_required, login_user, logout_user
from app import app
from app.forms import LoginForm
from flask_login import current_user, login_user, login_required
from app.models import User
@app.route("/")
@app.route("/index")
@login_required
def index():
user = {"username": "Miguel"}
return render_template("index.html", title="Home", user=user)
@app.route("/login", methods=["GET", "POST"])
def login():
if current_user.is_authenticated:
@@ -20,13 +29,7 @@ def login():
return render_template("login.html", title="Sign In", form=form)
@app.route("/")
@app.route("/index")
@login_required
def index():
user = {"username": "Miguel"}
posts = [
{"author": {"username": "John"}, "body": "Beautiful day in Portland!"},
{"author": {"username": "Susan"}, "body": "The Avengers movie was so cool!"},
]
return render_template("index.html", title="Home", user=user, posts=posts)
@app.route("/logout")
def logout():
logout_user()
return redirect(url_for("index"))