Specifying Webstorm environment from file? - webstorm

Is it possible to specify the environmental variables for Webstorm using, for example, a .env file? Where a .env file is a file of just key-value pairs like KEY=value.

Related

.Env file in Django project

I write this lines in .env file in django project to link my project to my Data base
but visual code make a problem to the file
Remove "export" from your .env file.
DB_NAME=IncomSpendsDB
DB_USER=postgres
DB_PASSWORD='0000000'
DB_HOST=localhost
https://djangocentral.com/environment-variables-in-django/

Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add '127.0.0.1' to ALLOWED_HOSTS

I keep on getting this error whenever I run my server locally.
This is how allowed hosts is in my .env file ALLOWED_HOSTS=['*']
I have tried adding '127.0.0.1' to the .env file instead of * but nothing seems to be working.Any ideas?
Django doesn't read .env file by itself. You should care about it.
If you want Django reading environment variables, you should use os.environ.get() method at your settings.py. But environment variables must be available for django. Export it at command line or provide .env file to your docker container.
Also, you can use this library: https://django-environ.readthedocs.io/en/latest/

Flask is not able to read my environment variable

I want to automatically import my FLASK_APP environment variable when running the Windows cmd.
I installed the python-dotenv, then created an .env file under my project main path.
However, I kept getting errors saying " Could not locate Flask application. You did not provide the FLASK_APP environment variable."
The following is the path I have for my project
project Path
And my .env is saved under the same path "Flask Virtue Environment\env\Voting Platform\Voting_Platform"
my .env file has the following code
FLASK_APP=runserver.py
Also I ran the following command to test if dotenv is able to locate my Environment File. I think it did find the file. (see below)
dotenv test
I am confused why the flask isn't able to read my .env file
I never develop flask in windows, but you can read this document to get clue for you problem.
Happy coding.

How to get the .env file into the remote host server

Quick question how to get the .env conf file into the server.
I have three settings file in my project base, development, production. I think testing and staging is an overkill
It is encouraged to put .env in .gitignore file. so it won't be included in version control. in Heroku, it is easy to set the environment variable in the settings tab. what about other hosting services without such a feature? since I push to my repository and pull from the server, How I am I suppose to get the API keys stored in the .env since it will ignore it (it's in gitignore) file? should I create in the server? or is there a way it is done? Newbie question I know.
You are correct. You should put your .env file in .gitignore and create .env file on server manually - either by connecting to server (SSH) and creating file or transfer file using one of secure transfer protocols (SCP, SFTP).

Laravel and environment variables in command line production without .env file

When I upgraded to Laravel 5 I started using the env system where I set all my configurations inside this file at the root.
.env
DB_HOST=x.x.x.x.x
DB_USERNAME
...
This file is not part of my repo and when I deploy I set the same variables onto my system environment variables (using amazon beanstalk here) so they are accessible without the need of the .env file.
So that all works but now when I use the command line in my scripts in production these system environment variables don't seem to be accessible in the command line. They are however accessible when the PHP is served through the web server.
I found if I copy add back this .env file then it works in the command line but that's why I'm confused, I thought this system was to prevent committing sensitive information to the repo and now it seems I have to do so so that I can use my php artisan migrate and other commands in production.
Am I missing something? Is there a way to get the system environment variables available in the command line or do I have to somehow create that .env file dynamically in production?
I always thought that the .env file was just part of setting up your server. The .env file is ignored by git, so once it's setup, you can push/pull to your heart's content and it'll leave the .env file alone. That's at least how I've done it so far.