Skip to main content

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的值加载为django的DJANGO_KEY1配置项。
  • 环境变量值使用YAML格式编写。

版本

v0.1.0

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

v0.1.1

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

v0.1.2

  • 修正:需要忽略DJANGO_SETTINGS_MODULE配置项的问题。

Release files for django-environ-settings 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-environ-settings 0.1.2
File Size Uploaded
django_environ_settings-0.1.2.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-environ-settings 0.1.2
File Interpreter ABI Platform
django_environ_settings-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.6 kB

Release files / django_environ_settings-0.1.2.tar.gz

Download URL django_environ_settings-0.1.2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
85b59c93cfb4cedaca750d9845367b12082cea3719df36f2c230e1f6dc9799d2
BLAKE2b-256 checksum
How to use checksums
edb9243e47ec87f711da81fff1052a9de34eaef098eb7c3acd584dfad76c7008
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / django_environ_settings-0.1.2-py3-none-any.whl

Download URL django_environ_settings-0.1.2-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fc5da2ea5d1b635e8016b6d06b96cc9635882b98d96d8f72f85dde0bed1f4f5
BLAKE2b-256 checksum
How to use checksums
99ae94ddc2224b6d004f3e6b04b05d7ed9894317201ceb2a3dc3b37aa30372e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page