<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有什么用?

        What is the use of python-dotenv?(python-dotenv有什么用?)
          <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有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

                    • <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'>

                          <tbody id='rSl78'></tbody>

                          <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>