本文整理匯總了Python中django.conf.settings.FILE_CHARSET屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.FILE_CHARSET屬性的具體用法?Python settings.FILE_CHARSET怎麽用?Python settings.FILE_CHARSET使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.FILE_CHARSET屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_template
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def get_template(self, template_name):
tried = []
for template_file in self.iter_template_filenames(template_name):
try:
with io.open(template_file, encoding=settings.FILE_CHARSET) as fp:
template_code = fp.read()
except IOError as e:
if e.errno == errno.ENOENT:
tried.append((
Origin(template_file, template_name, self),
'Source does not exist',
))
continue
raise
return Template(template_code)
else:
raise TemplateDoesNotExist(template_name, tried=tried, backend=self)
示例2: load_template_source
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def load_template_source(self, template_name, template_dirs=None):
"""
Loads templates from Python eggs via pkg_resource.resource_string.
For every installed app, it tries to get the resource (app, template_name).
"""
if resource_string is not None:
pkg_name = 'templates/' + template_name
for app in settings.INSTALLED_APPS:
try:
resource = resource_string(app, pkg_name)
except Exception:
continue
if not six.PY3:
resource = resource.decode(settings.FILE_CHARSET)
return (resource, 'egg:%s:%s' % (app, pkg_name))
raise TemplateDoesNotExist(template_name)
示例3: custom_sql_for_model
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def custom_sql_for_model(model, style, connection):
opts = model._meta
app_dir = os.path.normpath(os.path.join(os.path.dirname(upath(models.get_app(model._meta.app_label).__file__)), 'sql'))
output = []
# Post-creation SQL should come before any initial SQL data is loaded.
# However, this should not be done for models that are unmanaged or
# for fields that are part of a parent model (via model inheritance).
if opts.managed:
post_sql_fields = [f for f in opts.local_fields if hasattr(f, 'post_create_sql')]
for f in post_sql_fields:
output.extend(f.post_create_sql(style, model._meta.db_table))
# Find custom SQL, if it's available.
backend_name = connection.settings_dict['ENGINE'].split('.')[-1]
sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)),
os.path.join(app_dir, "%s.sql" % opts.object_name.lower())]
for sql_file in sql_files:
if os.path.exists(sql_file):
with codecs.open(sql_file, 'U', encoding=settings.FILE_CHARSET) as fp:
# Some backends can't execute more than one SQL statement at a time,
# so split into separate statements.
output.extend(_split_statements(fp.read()))
return output
示例4: read_template_source
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def read_template_source(filename):
"""Read the source of a Django template, returning the Unicode text."""
# Import this late to be sure we don't trigger settings machinery too
# early.
from django.conf import settings
if not settings.configured:
settings.configure()
with open(filename, "rb") as f:
# The FILE_CHARSET setting will be removed in 3.1:
# https://docs.djangoproject.com/en/3.0/ref/settings/#file-charset
if django.VERSION >= (3, 1):
charset = 'utf-8'
else:
charset = settings.FILE_CHARSET
text = f.read().decode(charset)
return text
示例5: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def __init__(self, params):
params = params.copy()
options = params.pop('OPTIONS').copy()
options.setdefault('debug', settings.DEBUG)
options.setdefault('file_charset', settings.FILE_CHARSET)
super(DjangoTemplates, self).__init__(params)
self.engine = Engine(self.dirs, self.app_dirs, **options)
示例6: get_template
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def get_template(self, template_name):
for template_file in self.iter_template_filenames(template_name):
try:
with io.open(template_file, encoding=settings.FILE_CHARSET) as fp:
template_code = fp.read()
except IOError:
continue
return Template(template_code)
else:
raise TemplateDoesNotExist(template_name)
示例7: custom_sql_for_model
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def custom_sql_for_model(model, style, connection):
opts = model._meta
app_dirs = []
app_dir = apps.get_app_config(model._meta.app_label).path
app_dirs.append(os.path.normpath(os.path.join(app_dir, 'sql')))
# Deprecated location -- remove in Django 1.9
old_app_dir = os.path.normpath(os.path.join(app_dir, 'models/sql'))
if os.path.exists(old_app_dir):
warnings.warn("Custom SQL location '<app_label>/models/sql' is "
"deprecated, use '<app_label>/sql' instead.",
RemovedInDjango19Warning)
app_dirs.append(old_app_dir)
output = []
# Post-creation SQL should come before any initial SQL data is loaded.
# However, this should not be done for models that are unmanaged or
# for fields that are part of a parent model (via model inheritance).
if opts.managed:
post_sql_fields = [f for f in opts.local_fields if hasattr(f, 'post_create_sql')]
for f in post_sql_fields:
output.extend(f.post_create_sql(style, model._meta.db_table))
# Find custom SQL, if it's available.
backend_name = connection.settings_dict['ENGINE'].split('.')[-1]
sql_files = []
for app_dir in app_dirs:
sql_files.append(os.path.join(app_dir, "%s.%s.sql" % (opts.model_name, backend_name)))
sql_files.append(os.path.join(app_dir, "%s.sql" % opts.model_name))
for sql_file in sql_files:
if os.path.exists(sql_file):
with io.open(sql_file, encoding=settings.FILE_CHARSET) as fp:
output.extend(connection.ops.prepare_sql_script(fp.read(), _allow_fallback=True))
return output
示例8: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def __init__(self, params):
params = params.copy()
options = params.pop('OPTIONS').copy()
options.setdefault('autoescape', True)
options.setdefault('debug', settings.DEBUG)
options.setdefault('file_charset', settings.FILE_CHARSET)
libraries = options.get('libraries', {})
options['libraries'] = self.get_templatetag_libraries(libraries)
super().__init__(params)
self.engine = Engine(self.dirs, self.app_dirs, **options)
示例9: get_template
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def get_template(self, template_name):
tried = []
for template_file in self.iter_template_filenames(template_name):
try:
with open(template_file, encoding=settings.FILE_CHARSET) as fp:
template_code = fp.read()
except FileNotFoundError:
tried.append((
Origin(template_file, template_name, self),
'Source does not exist',
))
else:
return Template(template_code)
raise TemplateDoesNotExist(template_name, tried=tried, backend=self)
示例10: load_template_source
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def load_template_source(self, template_name, template_dirs=None):
themes = Theme.objects.filter(enabled=True)
for theme in themes:
filepath = os.path.join(os.path.dirname(__file__), 'themes', theme.name, 'templates', template_name)
try:
file = open(filepath)
try:
return (file.read().decode(settings.FILE_CHARSET), filepath)
finally:
file.close()
except IOError:
pass
raise TemplateDoesNotExist("Could not find template '%s'." % template_name)
示例11: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def __init__(self, params):
params = params.copy()
options = params.pop('OPTIONS').copy()
options.setdefault('autoescape', True)
options.setdefault('debug', settings.DEBUG)
options.setdefault('file_charset', settings.FILE_CHARSET)
libraries = options.get('libraries', {})
options['libraries'] = self.get_templatetag_libraries(libraries)
super(DjangoTemplates, self).__init__(params)
self.engine = Engine(self.dirs, self.app_dirs, **options)
示例12: load_template_source
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def load_template_source(self, template_name, template_dirs=None):
for filepath in self.get_template_sources(template_name, template_dirs):
try:
with open(filepath, 'rb') as fp:
return (fp.read().decode(settings.FILE_CHARSET), filepath)
except IOError:
pass
raise TemplateDoesNotExist(template_name)
示例13: load_template_source
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def load_template_source(self, template_name, template_dirs=None):
tried = []
for filepath in self.get_template_sources(template_name, template_dirs):
try:
with open(filepath, 'rb') as fp:
return (fp.read().decode(settings.FILE_CHARSET), filepath)
except IOError:
tried.append(filepath)
if tried:
error_msg = "Tried %s" % tried
else:
error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
raise TemplateDoesNotExist(error_msg)
示例14: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def __init__(self, params):
params = params.copy()
options = params.pop('OPTIONS').copy()
options.setdefault('debug', settings.DEBUG)
options.setdefault('file_charset', settings.FILE_CHARSET)
libraries = options.get('libraries', {})
options['libraries'] = self.get_templatetag_libraries(libraries)
super(DjangoTemplates, self).__init__(params)
self.engine = Engine(self.dirs, self.app_dirs, **options)
示例15: test_override_settings_warning
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import FILE_CHARSET [as 別名]
def test_override_settings_warning(self):
with self.assertRaisesMessage(RemovedInDjango31Warning, self.msg):
with self.settings(FILE_CHARSET='latin1'):
pass