python - Flask application on google app engine - Showing database object -
i'm trying make flask app on google app engine shows database entries on own page.
this bit of views.py code:
@app.route('/posts/<int:id>') def display_post(id): post = post.filter('id =', id) return render_template('display_post.html', post=post)
then display_posts.html
{% extends "base.html" %} {% block content %} <ul> <h1 id="">post</h1> <li> {{ posts.title }}<br /> {{ posts.content }} </li> </ul> {% endblock %}
now when have post id 5700305828184064 , visit page should see title , content:
www.url.com/posts/5700305828184064
however traceback:
<type 'exceptions.attributeerror'>: type object 'post' has no attribute 'filter' traceback (most recent call last): file "/base/data/home/apps/s~smart-cove-95709/1.384741962561717132/main.py", line 4, in <module> run_wsgi_app(app) file "/base/data/home/runtimes/python/python_lib/versions/1/google/appengine/ext/webapp/util.py", line 99, in run_wsgi_app run_bare_wsgi_app(add_wsgi_middleware(application)) file "/base/data/home/runtimes/python/python_lib/versions/1/google/appengine/ext/webapp/util.py", line 117, in run_bare_wsgi_app result = application(env, _start_response) file "/base/data/home/apps/s~smart-cove-95709/1.384741962561717132/flask/app.py", line 874, in __call__ return self.wsgi_app(environ, start_response) file "/base/data/home/apps/s~smart-cove-95709/1.384741962561717132/flask/app.py", line 864, in wsgi_app response = self.make_response(self.handle_exception(e)) file "/base/data/home/apps/s~smart-cove-95709/1.384741962561717132/flask/app.py", line 861, in wsgi_app rv = self.dispatch_request() file "/base/data/home/apps/s~smart-cove-95709/1.384741962561717132/flask/app.py", line 696, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) file "/base/data/home/apps/s~smart-cove-95709/1.384741962561717132/blog/views.py", line 25, in display_post post = post.filter('id =', id)
how can show title , content of entry given id?
you need create query object first, apply filter that.
q = post.all() post = q.filter("id =", id)
this first example in gae docs on queries.
also, template references name posts
, you've passed in name post
. change template appropriately.
Comments
Post a Comment