本文整理汇总了Python中app.Application.db方法的典型用法代码示例。如果您正苦于以下问题:Python Application.db方法的具体用法?Python Application.db怎么用?Python Application.db使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.Application
的用法示例。
在下文中一共展示了Application.db方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Application
# 需要导入模块: from app import Application [as 别名]
# 或者: from app.Application import db [as 别名]
"""
from app import Application, Account
from gluon import current
from gluon.sqlhtml import SQLFORM
from gluon.dal import Field
from gluon.validators import IS_IMAGE
from gluon.html import URL
from gluon.http import redirect
try:
application = current.app
except:
application = Application()
application.db(models=[Account])
@application.auth.requires_membership("admin")
def check_logged():
return "I am logged in"
def has_session():
session = current.session
if "my_session" in session:
return "The session exists"
else:
return "The session does not exist"
示例2: define
# 需要导入模块: from app import Application [as 别名]
# 或者: from app.Application import db [as 别名]
import momoko
import psycopg2.extras
import config
from app import Application
from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)
if __name__ == "__main__":
tornado.options.parse_command_line()
app = Application()
ioloop = tornado.ioloop.IOLoop.instance()
app.db = momoko.Pool(
dsn='dbname={} user={} password={} host={} port={}'.format(
config.DATABASE_NAME,
config.DATABASE_USER,
config.DATABASE_PASSWORD,
config.DATABASE_HOST,
config.DATABASE_PORT),
cursor_factory=psycopg2.extras.RealDictCursor,
size=1,
ioloop=ioloop)
future = app.db.connect()
ioloop.add_future(future, lambda f: ioloop.stop())
ioloop.start()
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
ioloop.start()
示例3:
# 需要导入模块: from app import Application [as 别名]
# 或者: from app.Application import db [as 别名]
),
mail=Storage(
server='logging',
sender='[email protected]'
),
upload_folder=os.path.join(os.getcwd(), 'uploads')
))
from test_controllers import default_test, admin_test
logging.config.fileConfig('logging.conf')
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(default_test.DefaultTest))
suite.addTest(unittest.makeSuite(admin_test.AdminTest))
unittest.TextTestRunner(verbosity=1).run(suite)
# clean up
db = application.db()
for table in db.tables:
db[table].drop()
for db_file in os.listdir('databases'):
os.remove(os.path.abspath(os.path.join('databases', db_file)))
for test_file in os.listdir('uploads'):
os.remove(os.path.abspath(os.path.join('uploads', test_file)))
os.remove(os.path.join('logs', 'web2py.log'))