本文整理汇总了Python中settings.DATABASE属性的典型用法代码示例。如果您正苦于以下问题:Python settings.DATABASE属性的具体用法?Python settings.DATABASE怎么用?Python settings.DATABASE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类settings
的用法示例。
在下文中一共展示了settings.DATABASE属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clear_database
# 需要导入模块: import settings [as 别名]
# 或者: from settings import DATABASE [as 别名]
def clear_database():
assert settings.TEST_SETTINGS
if os.path.exists(settings.DATABASE):
os.remove(settings.DATABASE)
示例2: create
# 需要导入模块: import settings [as 别名]
# 或者: from settings import DATABASE [as 别名]
def create(cls, creator_id, message, locale='en', vote_options=[],
secret=False, public=False, max_votes=1, bars=False):
"""Creates a new poll without any votes.
Empty vote_options will be replaced by ['Yes', 'No'].
"""
con = sqlite3.connect(settings.DATABASE)
init_database(con)
cur = con.cursor()
if not vote_options:
with force_locale(locale):
vote_options = [tr('Yes'), tr('No')]
# clamp to 1 to len(vote_options)
max_votes = max(1, min(max_votes, len(vote_options)))
cur.execute("""INSERT INTO Polls
(creator, message, locale, finished,
secret, public, max_votes, bars) VALUES
(?, ?, ?, ?, ?, ?, ?, ?)""",
(creator_id, message, locale, False,
secret, public, max_votes, bars))
id = cur.lastrowid
for number, name in enumerate(vote_options):
cur.execute("""INSERT INTO VoteOptions
(poll_id, name, number) VALUES
(?, ?, ?)""",
(id, name, number))
con.commit()
return cls(con, id)
示例3: load
# 需要导入模块: import settings [as 别名]
# 或者: from settings import DATABASE [as 别名]
def load(cls, id):
"""Loads a poll from the database.
Raise a InvalidPollError if no poll with that id
exists.
"""
con = sqlite3.connect(settings.DATABASE)
return cls(con, id)
示例4: create_app
# 需要导入模块: import settings [as 别名]
# 或者: from settings import DATABASE [as 别名]
def create_app(loop):
app = web.Application(loop=loop, debug=settings.DEBUG)
setup_jinja(app, settings.DEBUG)
aiohttp_session.setup(app, EncryptedCookieStorage(
settings.SESSION_SECRET.encode('utf-8'),
max_age=settings.SESSION_MAX_AGE))
app.middlewares.append(aiohttp_login.flash.middleware)
app.router.add_get('/', handlers.index)
app.router.add_get('/users/', handlers.users, name='users')
app['db'] = await asyncpg.create_pool(dsn=settings.DATABASE, loop=loop)
aiohttp_login.setup(app, AsyncpgStorage(app['db']), settings.AUTH)
return app
示例5: __init__
# 需要导入模块: import settings [as 别名]
# 或者: from settings import DATABASE [as 别名]
def __init__(self, channels_amount, channels, log_filename=None):
self.bots = []
self.channels_amount = channels_amount
self.log_filename = log_filename
self.channels = channels
self.db_logger = DatabaseLogger(settings.DATABASE['HOST'],
settings.DATABASE['NAME'],
settings.DATABASE['USER'],
settings.DATABASE['PASSWORD'])
示例6: _create_bot
# 需要导入模块: import settings [as 别名]
# 或者: from settings import DATABASE [as 别名]
def _create_bot(self, name, channels):
conn = IRCConnection(settings.IRC['SERVER'],
settings.IRC['PORT'],
settings.IRC['NICK'],
settings.IRC['PASSWORD'],
self.log_filename)
bot_db_logger = DatabaseLogger(settings.DATABASE['HOST'],
settings.DATABASE['NAME'],
settings.DATABASE['USER'],
settings.DATABASE['PASSWORD'])
bot = TwitchBot(name, conn, bot_db_logger, Queue.Queue(), self.log_filename)
bot.daemon = True
bot.connect_and_join_channels(channels)
bot.start()
return bot