mirror of
https://github.com/rmontanana/microblog.git
synced 2025-08-18 00:35:51 +00:00
Chapter 4
This commit is contained in:
27
app/routes.py
Normal file
27
app/routes.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from flask import render_template, flash, redirect, url_for
|
||||
from app import app
|
||||
from app.forms import LoginForm
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@app.route("/index")
|
||||
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("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
flash(
|
||||
"Login requested for user {}, remember_me={}".format(
|
||||
form.username.data, form.remember_me.data
|
||||
)
|
||||
)
|
||||
return redirect(url_for("index"))
|
||||
return render_template("login.html", title="Sign In", form=form)
|
Reference in New Issue
Block a user