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


Python settings.FILE_CHARSET属性代码示例

本文整理汇总了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) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:21,代码来源:dummy.py

示例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) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:19,代码来源:eggs.py

示例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 
开发者ID:blackye,项目名称:luscan-devel,代码行数:26,代码来源:sql.py

示例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 
开发者ID:nedbat,项目名称:django_coverage_plugin,代码行数:21,代码来源:plugin.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,代码来源:django.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:14,代码来源:dummy.py

示例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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:37,代码来源:sql.py

示例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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:12,代码来源:django.py

示例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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:16,代码来源:dummy.py

示例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) 
开发者ID:MicroPyramid,项目名称:django-blog-it,代码行数:17,代码来源:loaders.py

示例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) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:12,代码来源:django.py

示例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) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:10,代码来源:app_directories.py

示例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) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:15,代码来源:filesystem.py

示例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) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:11,代码来源:django.py

示例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 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_file_charset.py


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