How to set DATABASE_URL environment variable for Postgres Mac terminal?

旧时模样 提交于 2021-02-11 14:45:19

问题


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


回答1:


Yes, you have to do that manually. So, within your terminal do this:

% cd
% nano .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"

Check this video out for more info: https://youtu.be/5iWhQWVXosU



来源:https://stackoverflow.com/questions/61901732/how-to-set-database-url-environment-variable-for-postgres-mac-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!