Permalink
Browse files

Hooking up Data

  • Loading branch information...
1 parent d113732 commit 1b5fbbcd5523540057788e724439502e99fad401 @eleddy eleddy committed Jan 11, 2012
Showing with 37 additions and 9 deletions.
  1. +28 −5 README.rst
  2. +6 −1 src/noiselist/__init__.py
  3. +3 −3 src/noiselist/templates/hello.html
View
33 README.rst
@@ -157,14 +157,37 @@ This is just a basic logo that let's us know that we are serving up the correct
Let's update our front page to use bootstraps styles. For brevity I will just point to
the raw source since its a lot. Update hello.html with the code at::
- XXX: Put link here
+ https://raw.github.com/eleddy/flask-noiselist/d1137326c11cb908ddc6d59598913e439d5b1f83/src/noiselist/templates/hello.html
-Deployment
-----------
-Flask is run under WSGI. We will discuss what that means in other classes, but
-more importantly you just need to know that routing occurs outside of the app itself***
+Reload and party.
+
+Hooking up to Data
+------------------
+Flask passes arguments to the templating language just like web2 py does. To quickly
+pass in a list of items to display on the front page, update __init__.py to say::
+
+ def index():
+ todo_list = ["Watch TV",
+ "Contemplate Work",
+ "Go to Bed",
+ ]
+ return render_template('hello.html', todos=todo_list)
+Then in hello.html we update the list to pull from the todos passed in::
+ <h2>Current TODOs</h2>
+ <ul>
+ {% for todo in todos %}
+ <li>{{ todo }}</li>
+ {% endfor %}
+ <ul>
+
+Note the difference in syntax here with web2py. To end a loop we use "endfor" instead
+of "pass". The = is not required to display a variable either.
+
+
+The Database
+------------
More Info
View
7 src/noiselist/__init__.py
@@ -2,6 +2,7 @@
from flask import Flask, request
from flask import render_template
+
class _DefaultSettings(object):
USERNAME = 'world'
SECRET_KEY = 'development key'
@@ -21,5 +22,9 @@ def init_db():
@app.route('/')
def index():
- return render_template('hello.html')
+ todo_list = ["Watch TV",
+ "Contemplate Work",
+ "Go to Bed",
+ ]
+ return render_template('hello.html', todos=todo_list)
View
6 src/noiselist/templates/hello.html
@@ -33,9 +33,9 @@
<div class="span10">
<h2>Current TODOs</h2>
<ul>
- <li>Finish evaluating pull requests</li>
- <li>Finish writing up class work</li>
- <li>Swim and enjoy the sun</li>
+ {% for todo in todos %}
+ <li>{{ todo }}</li>
+ {% endfor %}
<ul>
<form action="" method="POST" id="add_to_todo_list">
<input type="text" name="todo_item"/>

0 comments on commit 1b5fbbc

Please sign in to comment.