templates

This commit is contained in:
Miguel Grinberg 2012-12-16 00:26:19 -08:00
parent 79e9810b62
commit a1fa2715ad
3 changed files with 39 additions and 1 deletions

14
app/templates/base.html Normal file
View File

@ -0,0 +1,14 @@
<html>
<head>
{% if title %}
<title>{{title}} - microblog</title>
{% else %}
<title>microblog</title>
{% endif %}
</head>
<body>
<div>Microblog: <a href="/index">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
</html>

9
app/templates/index.html Normal file
View File

@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block content %}
<h1>Hi, {{user.nickname}}!</h1>
{% for post in posts %}
<p>
{{post.author.nickname}} says: <b>{{post.body}}</b>
</p>
{% endfor %}
{% endblock %}

View File

@ -1,6 +1,21 @@
from flask import render_template
from app import app from app import app
@app.route('/') @app.route('/')
@app.route('/index') @app.route('/index')
def index(): def index():
return "Hello, World!" user = { 'nickname': 'Miguel' }
posts = [
{
'author': { 'nickname': 'John' },
'body': 'Beautiful day in Portland!'
},
{
'author': { 'nickname': 'Susan' },
'body': 'The Avengers movie was so cool!'
}
]
return render_template("index.html",
title = 'Home',
user = user,
posts = posts)