menu

Saleor Commerce

The world’s fastest growing open-source e-commerce platform with billions of dollars transacted. Powered by Python, GraphQL, ReactJS and PWA.

Channels
# All channels
view-forward
# General
view-forward
# Announcements
view-forward
# Design
view-forward
# Development
view-forward
# Saleor 3.0
view-forward
# Saleor Features
view-forward
Team

How can i setup environment variables using .env?

July 7, 2020 at 7:02pm

How can i setup environment variables using .env?

July 7, 2020 at 7:02pm
I would like to setup (SECRET_KEY & DATABASE_URL etc) instead of editing settings.py directly. Can someone help me with it?

July 7, 2020 at 7:17pm
so there is no way to set up via .env file.
  • reply
  • like

July 8, 2020 at 7:52am
Hey Karol! I did try to use direnv to save variables permanent. I use DEBUG=False & also set the ALLOWED_CLIENT_HOSTS but when i try to run it still giving error django.core.exceptions.ImproperlyConfigured: ALLOWED_CLIENT_HOSTS environment variable must be set when DEBUG=False
export DEBUG=False export ALLOWED_GRAPHQL_ORIGINS="*" export ALLOWED_HOSTS="api.domain.com" export ALLOWED_CLIENT_HOSTS="api.domain.com"
  • reply
  • like
This below is just a hack if you really want to use only .env via python-decouple.
like-fill
1
  • reply
  • like
Or if you want to use to bashrc file to set your env variables, ref below : https://gist.github.com/neerajgupta2407/e809e5d966be469dc8de105b7656389c
  • reply
  • like
  • reply
  • like
so there is no way to set up via .env file.
when you login, it executes the .bashrc so your ENV Variables are always set.
  • reply
  • like

July 14, 2020 at 8:06pm
For local development direnv is godsend https://direnv.net/ I really do not recommend setting up those variables in your own .bashrc. This way every terminal window will have those vars set, which can lead to problems if you develop multiple apps. Using direnv eliminates such issue - when you leave project directory, it clears any variables you changed.
  • reply
  • like
For local development direnv is godsend https://direnv.net/ I really do not recommend setting up those variables in your own .bashrc. This way every terminal window will have those vars set, which can lead to problems if you develop multiple apps. Using direnv eliminates such issue - when you leave project directory, it clears any variables you changed.
I'm setting env variables in uwsgi.ini file for the production.
  • reply
  • like

July 15, 2020 at 7:25am
Setting .env variable in uwsgi file may lead to pushing the credentials to your git repo which is not recommended for production. If this is not the case, then you can ignore this msg.
  • reply
  • like
Setting .env variable in uwsgi file may lead to pushing the credentials to your git repo which is not recommended for production. If this is not the case, then you can ignore this msg.
for now i did add variables manually to uwsgi.ini. In case of git which way would you recommend?
  • reply
  • like
ideally you should create a separate file like .env and load it via decouple module. Refer this: https://gist.github.com/neerajgupta2407/762c93ff3aac588ff53f62baa67801cc
  • reply
  • like