Permalink
Browse files

changed sample to demo using DataStore

  • Loading branch information...
jugyo committed Aug 5, 2010
1 parent d6152f2 commit 6ae5fe79e649d5d92ea0d20150b46e2252f81f3b
Showing with 31 additions and 20 deletions.
  1. +0 −1 README.md
  2. +14 −9 app.py
  3. +7 −0 models.py
  4. +1 −3 static/screen.css
  5. +0 −4 templates/hello.html
  6. +9 −3 templates/index.html
View
@@ -25,7 +25,6 @@ You should fix application name of app.yaml before deploy.
TODO
------
-* sample for using DataStore
* sample for test
See Also
View
23 app.py
@@ -1,16 +1,21 @@
-from flask import Flask
-from flask import render_template, request
+#
+# Flask Documentation: http://flask.pocoo.org/docs/
+# Jinja2 Documentation: http://jinja.pocoo.org/2/documentation/
+# Werkzeug Documentation: http://werkzeug.pocoo.org/documentation/
+# The Python Datastore API: http://code.google.com/appengine/docs/python/datastore/
+#
-# if necessary
-# from flask import redirect, url_for, session,\
-# abort, flash, get_flashed_messages, g, Response\
+from flask import Flask, url_for, render_template, request, redirect
+from models import *
app = Flask(__name__)
@app.route('/')
def index():
- return render_template('index.html')
+ return render_template('index.html', todos=Todo.all().order('-created_at'))
-@app.route('/hello')
-def hello():
- return render_template('hello.html', name=request.args.get('name'))
+@app.route('/add', methods=["POST"])
+def add():
+ todo = Todo(text=request.form['text'])
+ todo.save()
+ return redirect(url_for('index'))
View
@@ -0,0 +1,7 @@
+# The Python Datastore API: http://code.google.com/appengine/docs/python/datastore/
+
+from google.appengine.ext import db
+
+class Todo(db.Model):
+ text = db.StringProperty()
+ created_at = db.DateTimeProperty(auto_now=True)
View
@@ -1,6 +1,4 @@
body {
- width: 600px;
- margin: 60px auto;
- text-align: center;
+ margin: 60px;
font-family: 'Lucida Grande', sans-serif;
}
View
@@ -1,4 +0,0 @@
-{% extends "layout.html" %}
-{% block body %}
- <div class="content">Hello {{ name }}!</div>
-{% endblock %}
View
@@ -1,7 +1,13 @@
{% extends "layout.html" %}
{% block body %}
- <form action="{{ url_for('hello') }}" method="get">
- <input type="text" name="name" />
- <input type="submit" value="hello"/>
+ <form action="{{ url_for('add') }}" method="post">
+ <input type="text" name="text" />
+ <input type="submit" value="add"/>
</form>
+
+ <ul>
+ {% for todo in todos %}
+ <li>{{ todo.text }}</li>
+ {% endfor %}
+ </ul>
{% endblock %}

0 comments on commit 6ae5fe7

Please sign in to comment.