From a1fa2715ad643a1d14d88759d83b98196200bc44 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sun, 16 Dec 2012 00:26:19 -0800 Subject: [PATCH] templates --- app/templates/base.html | 14 ++++++++++++++ app/templates/index.html | 9 +++++++++ app/views.py | 17 ++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/templates/base.html create mode 100644 app/templates/index.html diff --git a/app/templates/base.html b/app/templates/base.html new file mode 100644 index 0000000..0fbd92f --- /dev/null +++ b/app/templates/base.html @@ -0,0 +1,14 @@ + + + {% if title %} + {{title}} - microblog + {% else %} + microblog + {% endif %} + + +
Microblog: Home
+
+ {% block content %}{% endblock %} + + \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..7fa8c8a --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block content %} +

Hi, {{user.nickname}}!

+{% for post in posts %} +

+ {{post.author.nickname}} says: {{post.body}} +

+{% endfor %} +{% endblock %} \ No newline at end of file diff --git a/app/views.py b/app/views.py index d467b15..7742496 100644 --- a/app/views.py +++ b/app/views.py @@ -1,6 +1,21 @@ +from flask import render_template from app import app @app.route('/') @app.route('/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)