本文整理匯總了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)
示例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)
示例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.")