为Python Web应用程序设置环境变量(To set up environmental variables for a Python web application)

编程入门 行业动态 更新时间:2024-10-27 03:34:48
为Python Web应用程序设置环境变量(To set up environmental variables for a Python web application)

我需要设置以下env变量,以便我可以使用PostgreSQL的数据库程序

export PGDATA="/home/masi/postgres/var" export PGPORT="12428"

我知道可以通过将文件添加到.zshrc来解决问题。 但是,我不确定这是否是正确的路要走。

你如何添加env变量?

I need to set up the following env variables such that I can a database program which use PostgreSQL

export PGDATA="/home/masi/postgres/var" export PGPORT="12428"

I know that the problem may be solved by adding the files to .zshrc. However, I am not sure whether it is the right way to go.

How can you add env variables?

最满意答案

您只需要在启动服务器的脚本中设置PGDATA变量。 客户端只关心端口。

如果您必须在非标准端口上运行端口值,则必须设置端口值。 我假设你有一个很好的理由不只是在默认端口上运行它? 如果你确实在默认端口(5432)上运行它,那么它完全可以在没有任何参数的情况下运行。

如果您在其他端口上运行它,则应进行两项更改:

在postgresql.conf中,将port = value设置为所需的新端口,然后重新启动数据库服务器。 在django的settings.py中,将DATABASE_PORT值设置为所需的新端口。

你绝对不需要为这些简单的配置选项使用环境变量 - 避免它们会让你的生活更轻松。

You only need to set the PGDATA variable in the script that starts the server. The client only cares about the port.

You do have to set the port value if you must run it on a non-standard port. I assume you have a good reason to not just run it on the default port? If you do run it on the default port (5432), it will just work without any parameters for it at all.

If you are running it on a different port, you should make two changes:

In postgresql.conf, set the port= value to the new port you want, and restart the database server. In your settings.py in django, set the DATABASE_PORT value to the new port you want.

You should definitely not need to use environment variables for simple configuration options like these - avoiding them will make your life easier.

更多推荐

本文发布于:2023-08-06 14:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451144.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   环境变量   Python   Web   set

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!