0
我在用SqlAlchemy(通過Elixir)試圖使用Pylons。從模型對象查詢時出現問題
這裏是我的TESTDB /模型/ entities.py:
from elixir import *
metadata.bind = "mysql://testdb:[email protected]/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'
有人知道我在做什麼錯嗎?
那麼,你完全改變了這個問題後,我的答案看起來有點愚蠢... – 2011-02-07 16:55:23