当前位置: 首页>>代码示例>>Python>>正文


Python settings.DATABASE_ENGINE属性代码示例

本文整理汇总了Python中django.conf.settings.DATABASE_ENGINE属性的典型用法代码示例。如果您正苦于以下问题:Python settings.DATABASE_ENGINE属性的具体用法?Python settings.DATABASE_ENGINE怎么用?Python settings.DATABASE_ENGINE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.conf.settings的用法示例。


在下文中一共展示了settings.DATABASE_ENGINE属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: content

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DATABASE_ENGINE [as 别名]
def content(self):
        width_ratio_tally = 0
        for query in self._queries:
            query['sql'] = reformat_sql(query['sql'])
            try:
                query['width_ratio'] = (query['duration'] / self._sql_time) * 100
            except ZeroDivisionError:
                query['width_ratio'] = 0
            query['start_offset'] = width_ratio_tally
            width_ratio_tally += query['width_ratio']

        context = self.context.copy()
        context.update({
            'queries': self._queries,
            'sql_time': self._sql_time,
            'is_mysql': settings.DATABASE_ENGINE == 'mysql',
        })

        return render_to_string('debug_toolbar/panels/sql.html', context) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:21,代码来源:sql.py

示例2: main

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DATABASE_ENGINE [as 别名]
def main():
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ara.server.settings")

    try:
        from django.core.management import execute_from_command_line
    except ImportError as e:
        raise MissingDjangoException from e

    # Validate that the settings file exists and is readable before bootstrapping
    if not os.path.exists(settings.ARA_SETTINGS):
        print("[ara] Unable to access or read settings file: %s" % settings.ARA_SETTINGS)
        raise MissingSettingsException
    print("[ara] Using settings file: %s" % settings.ARA_SETTINGS)

    if settings.DATABASE_ENGINE == "django.db.backends.postgresql":
        try:
            import psycopg2  # noqa
        except ImportError as e:
            raise MissingPsycopgException from e

    if settings.DATABASE_ENGINE == "django.db.backends.mysql":
        try:
            import MySQLdb  # noqa
        except ImportError as e:
            raise MissingMysqlclientException from e

    execute_from_command_line(sys.argv) 
开发者ID:ansible-community,项目名称:ara,代码行数:29,代码来源:__main__.py

示例3: sql_explain

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DATABASE_ENGINE [as 别名]
def sql_explain(request):
    """
    Returns the output of the SQL EXPLAIN on the given query.

    Expected GET variables:
        sql: urlencoded sql with positional arguments
        params: JSON encoded parameter values
        duration: time for SQL to execute passed in from toolbar just for redisplay
        hash: the hash of (secret + sql + params) for tamper checking
    """
    from debug_toolbar.panels.sql import reformat_sql
    sql = request.GET.get('sql', '')
    params = request.GET.get('params', '')
    hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
    if hash != request.GET.get('hash', ''):
        return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
    if sql.lower().strip().startswith('select'):
        params = simplejson.loads(params)
        cursor = connection.cursor()

        if settings.DATABASE_ENGINE == "sqlite3":
            # SQLite's EXPLAIN dumps the low-level opcodes generated for a query;
            # EXPLAIN QUERY PLAN dumps a more human-readable summary
            # See http://www.sqlite.org/lang_explain.html for details
            cursor.execute("EXPLAIN QUERY PLAN %s" % (sql,), params)
        else:
            cursor.execute("EXPLAIN %s" % (sql,), params)

        headers = [d[0] for d in cursor.description]
        result = cursor.fetchall()
        cursor.close()
        context = {
            'result': result,
            'sql': reformat_sql(cursor.db.ops.last_executed_query(cursor, sql, params)),
            'duration': request.GET.get('duration', 0.0),
            'headers': headers,
        }
        return render_to_response('debug_toolbar/panels/sql_explain.html', context)
    raise InvalidSQLError("Only 'select' queries are allowed.") 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:41,代码来源:views.py


注:本文中的django.conf.settings.DATABASE_ENGINE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。