如何为Postgres Mac终端设置DATABASE_URL环境变量? [英] How to set DATABASE_URL environment variable for Postgres Mac terminal?
问题描述
我在Mac上使用的是postgres.我有一个数据库并且正在运行.我想将其与Flask(SQL Alchemy)一起使用,但是 DATABASE_URL
环境变量并未创建自身(我认为应该这样做).这是我尝试运行的代码:
I am using postgres on Mac. I have a database up and running. I want to use it with Flask (SQL Alchemy) but the DATABASE_URL
environment variable didn't create itself (I think it's supposed to do that). Here is the code I tried running:
import os
print(os.getenv("DATABASE_URL"))
并且没有输出.如何设置变量(如果需要手动设置).
And there's no output. How can I set the variable (if I need to set it up manually).
推荐答案
是的,您必须手动执行此操作.因此,在您的终端中执行以下操作:
Yes, you have to do that manually. So, within your terminal do this:
% cd
% nano .bash_profile
它将在终端的编辑器中打开文件"bash_profile".在其中可以设置环境变量,例如:
It will open a file 'bash_profile' in editor in your terminal. And in there you can set environmental variables like:
export DATABASE_URL="YOUR DATABASE URL"
查看此视频以了解更多信息: https://youtu.be/5iWhQWVXosU
Check this video out for more info: https://youtu.be/5iWhQWVXosU
这篇关于如何为Postgres Mac终端设置DATABASE_URL环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!