當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。