我正在尝试将 Pylons 与 SqlAlchemy 一起使用(通过 Elixir)。
这是我的 testdb/model/entities.py:
from elixir import *
metadata.bind = "mysql://testdb:hundertwasser@localhost/testdb"
metadata.bind.echo = True
class Post(Entity):
text = Field(Unicode(128))
这是控制器:
import logging
from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect
from testdb.lib.base import BaseController, render
log = logging.getLogger(__name__)
from testdb.model.entities import *
class MainController(BaseController):
def index(self):
c.posts = Post.query.all()
print "Test"
return render('/index.mako')
def submit(self):
post = Post()
post.text = request.POST.get['text']
session.commit()
当我运行应用程序时,我收到一条错误消息:
AttributeError: type object 'Post' has no attribute 'query'
有人知道我做错了什么吗?