Home >Backend Development >Python Tutorial >How do you manage environment variables in PyCharm for Django development?
Setting Environment Variables in PyCharm for Django Development
When working with Django projects, it becomes necessary to set environment variables to configure database settings and other parameters. Instead of manually setting these variables or using external bash files, PyCharm offers a convenient way to manage environment variables within its run configurations menu.
To set environment variables in PyCharm:
For instance, to set the variables:
export DATABASE_URL=postgres://127.0.0.1:5432/my_db_name export DEBUG=1
Simply add them to the "Environmental variables" dialog box as key-value pairs:
DATABASE_URL=postgres://127.0.0.1:5432/my_db_name DEBUG=1
Once configured, the environment variables can be accessed within your code using the os.environ module. For example, to access the value of the DATABASE_URL variable:
<code class="python">import os print(os.environ['DATABASE_URL'])</code>
By setting environment variables directly in PyCharm's run configurations, you can streamline your Django development process and avoid the need for external configuration management.
The above is the detailed content of How do you manage environment variables in PyCharm for Django development?. For more information, please follow other related articles on the PHP Chinese website!