<bdo id='4vkbZ'></bdo><ul id='4vkbZ'></ul>

      1. <i id='4vkbZ'><tr id='4vkbZ'><dt id='4vkbZ'><q id='4vkbZ'><span id='4vkbZ'><b id='4vkbZ'><form id='4vkbZ'><ins id='4vkbZ'></ins><ul id='4vkbZ'></ul><sub id='4vkbZ'></sub></form><legend id='4vkbZ'></legend><bdo id='4vkbZ'><pre id='4vkbZ'><center id='4vkbZ'></center></pre></bdo></b><th id='4vkbZ'></th></span></q></dt></tr></i><div id='4vkbZ'><tfoot id='4vkbZ'></tfoot><dl id='4vkbZ'><fieldset id='4vkbZ'></fieldset></dl></div>

        <small id='4vkbZ'></small><noframes id='4vkbZ'>

        <tfoot id='4vkbZ'></tfoot>

      2. <legend id='4vkbZ'><style id='4vkbZ'><dir id='4vkbZ'><q id='4vkbZ'></q></dir></style></legend>

        python-dotenv有什么用?

        时间:2023-07-04
          <bdo id='5ij5V'></bdo><ul id='5ij5V'></ul>
        • <tfoot id='5ij5V'></tfoot>

            <legend id='5ij5V'><style id='5ij5V'><dir id='5ij5V'><q id='5ij5V'></q></dir></style></legend>
                <tbody id='5ij5V'></tbody>

                <small id='5ij5V'></small><noframes id='5ij5V'>

                <i id='5ij5V'><tr id='5ij5V'><dt id='5ij5V'><q id='5ij5V'><span id='5ij5V'><b id='5ij5V'><form id='5ij5V'><ins id='5ij5V'></ins><ul id='5ij5V'></ul><sub id='5ij5V'></sub></form><legend id='5ij5V'></legend><bdo id='5ij5V'><pre id='5ij5V'><center id='5ij5V'></center></pre></bdo></b><th id='5ij5V'></th></span></q></dt></tr></i><div id='5ij5V'><tfoot id='5ij5V'></tfoot><dl id='5ij5V'><fieldset id='5ij5V'></fieldset></dl></div>
                • 本文介绍了python-dotenv有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  需要一个例子,请解释一下 python-dotenv 的用途.
                  我对文档有点困惑.

                  Need an example and please explain me the purpose of python-dotenv.
                  I am kind of confused with the documentation.

                  推荐答案

                  来自 Github 页面:

                  从 .env 中读取键值对并将它们添加到环境变量中.使用 12 要素原则在开发和生产过程中管理应用设置非常有用.

                  Reads the key,value pair from .env and adds them to environment variable. It is great of managing app settings during development and in production using 12-factor principles.

                  假设您已在设置模块旁边创建了 .env 文件.

                  Assuming you have created the .env file along-side your settings module.

                  .
                  ├── .env
                  └── settings.py
                  

                  将以下代码添加到您的 settings.py 中

                  Add the following code to your settings.py

                  # settings.py
                  import os
                  from os.path import join, dirname
                  from dotenv import load_dotenv
                  
                  dotenv_path = join(dirname(__file__), '.env')
                  load_dotenv(dotenv_path)
                  
                  SECRET_KEY = os.environ.get("SECRET_KEY")
                  DATABASE_PASSWORD = os.environ.get("DATABASE_PASSWORD")
                  

                  .env 是一个简单的文本文件.每行列出每个环境变量,格式为 KEY="Value",忽略以 # 开头的行.

                  .env is a simple text file. With each environment variables listed per line, in the format of KEY="Value", lines starting with # is ignored.

                  SOME_VAR=someval
                  # I am a comment and that is OK
                  FOO="BAR"
                  

                  这篇关于python-dotenv有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何从 Github 工作流访问环境机密? 下一篇:如何从子进程中获取环境?

                  相关文章

                  • <bdo id='rSl78'></bdo><ul id='rSl78'></ul>
                • <legend id='rSl78'><style id='rSl78'><dir id='rSl78'><q id='rSl78'></q></dir></style></legend>

                  <small id='rSl78'></small><noframes id='rSl78'>

                    <tfoot id='rSl78'></tfoot>
                    1. <i id='rSl78'><tr id='rSl78'><dt id='rSl78'><q id='rSl78'><span id='rSl78'><b id='rSl78'><form id='rSl78'><ins id='rSl78'></ins><ul id='rSl78'></ul><sub id='rSl78'></sub></form><legend id='rSl78'></legend><bdo id='rSl78'><pre id='rSl78'><center id='rSl78'></center></pre></bdo></b><th id='rSl78'></th></span></q></dt></tr></i><div id='rSl78'><tfoot id='rSl78'></tfoot><dl id='rSl78'><fieldset id='rSl78'></fieldset></dl></div>