我的项目基于 Pyramid。
Pyramid 的默认脚手架非常简单:view.py
, models.py
, 等等。
我创建了一些目录来替换它们。例如:
view.py
--> 查看目录
models.py
--> 模型目录
然后我创建一个名为login.py
:
from pyramid.httpexceptions import HTTPForbidden
from pyramid.response import Response
from pyramid.view import view_config
import logging
from ..model import (
DBSession,
DynUser,
)
log = logging.getLogger(__name__)
def find_user(account):
#user = None
try:
user = DBSession.query(DynUser).filter(DynUser.username==account).first()
#one = DBSession.query(MyModel).filter(MyModel.name=='one').first()
except ValueError:
#log.warning("invalidate id %s input." % request.matchdict['id'])
log.warning("invalidate id %s input.")
except Exception:
log.error("database error!")
if not user:
return HTTPForbidden()
return dict(user=user)
我已经导入了 DBSession。为什么我仍然会收到此错误?
tip
--------------------------------------------------------------------------
Undefined variable from import: DBSession
Undefined variable from import: DBSession
DBSession Found at: dyncms.model.meta
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))