Chapter 2: Templates (v0.2)
This commit is contained in:
parent
e96a2e61f6
commit
538d8ab9a3
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<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>
|
|
@ -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 %}
|
Loading…
Reference in New Issue