Skip to content

Commit

Permalink
Chapter 2: Templates (v0.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jul 10, 2021
1 parent 23b3fc8 commit 5d45592
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
from flask import render_template
from app import app


@app.route('/')
@app.route('/index')
def index():
return "Hello, World!"
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)
15 changes: 15 additions & 0 deletions app/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
{% if title %}
<title>{{ title }} - Microblog</title>
{% else %}
<title>Welcome to Microblog</title>
{% endif %}
</head>
<body>
<div>Microblog: <a href="/index">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
</html>
8 changes: 8 additions & 0 deletions app/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}

{% block content %}
<h1>Hi, {{ user.username }}!</h1>
{% for post in posts %}
<div><p>{{ post.author.username }} says: <b>{{ post.body }}</b></p></div>
{% endfor %}
{% endblock %}

0 comments on commit 5d45592

Please sign in to comment.