2011-02-06 4 views
0

나는 Pylons를 (Elixir를 통해) SqlAlchemy와 함께 사용하려고합니다. 여기 모델 개체에서 쿼리하는 중 문제가 발생했습니다.

내 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' 

누군가 내가 뭘 잘못하고 있는지 알고 있습니까?

답변

1

대답은 :

entities.py이 아래쪽에 다음 두 줄이 누락되었습니다

setup_all() 
create_all() 
0

잘 모르겠 음 엘릭서는 잘 모르지만 .ini에 다음을 넣지는 않았습니까?

sqlalchemy.url = mysql://user:[email protected]/dbname?charset=utf8&use_unicode=0 
sqlalchemy.pool_recycle = 3600 

? 이후의 모든 내용은 인코딩 문제를 피하는 것입니다. 두 번째 줄은 MySQL이 비활성 연결을 닫는 것을 방지합니다 (실제로 매시간 다시 연결됩니다). 다음과 같이

+0

그럼 당신은 완전히 질문을 변경 한 후, 내 대답은 바보의 종류를 보이는 ... –