Skip to main content

从环境变量中加载Django配置项。

Project description

django-environ-settings

从环境变量中加载Django配置项。

安装

pip install django-environ-settings

使用方法

pro/settings.py结尾处添加以下代码:

from django_environ_settings import django_environ_settings_patch_all

django_environ_settings_patch_all(
    keys=["CONFIG_ITEM_KEY"],
    mapping_keys={
        "ENV_KEY1": "DJANGO_KEY1",
        "ENV_KEY2": "DJANGO_KEY2",
    }
    namespace="DJANGO_",
)
  • namespace="DJANGO_"表示只有以DJANGO_开头的环境变量才被django使用,并用于更新移除DJANGO_前缀后对应的配置项。
    • django中的数据库配置项DATABASES对应的环境变量为DJANGO_DATABASES
  • keys用于加载不使用namespace前缀的环境变量。允许为空。
    • CONFIG_ITEM_KEY表示在djaong.conf.settings中添加了额外的CONFIG_ITEM_KEY配置项。
    • 当前使用namespace前缀的环境变量DJANGO_CONFIG_ITEM_KEY也能实现相同效果,并且优先级更高。
  • mapping_keys用于处理环境变量名与django配置项名不一致的情况。
    • 如:把环境变量ENV_KEY1的值加载为djangoDJANGO_KEY1配置项。
  • 环境变量值使用YAML格式编写。

版本

v0.1.0

  • 版本首发,基本功能完成。

v0.1.1

  • 添加:内外部KEY值映射的支持。
  • 修正:打包后*.whl中没有包含有效代码的问题。
  • 修正:加载配置项时没有移除前缀的问题。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_environ_settings-0.1.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

django_environ_settings-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file django_environ_settings-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django_environ_settings-0.1.1.tar.gz
Algorithm Hash digest
SHA256 394e0c2c388f62d128e5629a44df8f99c2160dd87281e8c4e4900b253604af33
MD5 bb808ac9907e45963b3d08bf6beb88e3
BLAKE2b-256 c304095b47529756aee6aad9d3963897c0882631bb8033353ee514c37b44ab03

See more details on using hashes here.

File details

Details for the file django_environ_settings-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_environ_settings-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e173c769f2d4b60e6f7dbbd2ac5340895da1b85697b92a740c272b2e98ce7fdd
MD5 052649d644d9b519f1319d83c4aa307d
BLAKE2b-256 8bbd2d3a90ce4c6b58f6b56b92cad9bf003d844eed8565f13f62ba2fce48ab9f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page