# Import custom variable inside different Environment

**URL:** <https://forum.djangoproject.com/t/import-custom-variable-inside-different-environment/2978>\
**Category:** Using Django\
**Created:** [June 15, 2020, 1:57am UTC](https://forum.djangoproject.com/t/import-custom-variable-inside-different-environment/2978 "2020-06-15T01:57:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://forum.djangoproject.com/u/dev)\
**Post date:** [June 15, 2020, 1:57am UTC](https://forum.djangoproject.com/t/import-custom-variable-inside-different-environment/2978/1 "2020-06-15T01:57:29Z")

</div>

Hi  
I have different settings file for dev, testing and production. I also have custom variables inside these settings files. (values must be changing depends on env)

How can I import/get the correct value from the settings file depends on current environment?

Thank you

---

<div class="post-metadata">

**Author:** ![Suttonium](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/suttonium/32/1264_2.png) [@Suttonium](https://forum.djangoproject.com/u/Suttonium)\
**Post date:** [June 15, 2020, 6:53pm UTC](https://forum.djangoproject.com/t/import-custom-variable-inside-different-environment/2978/2 "2020-06-15T18:53:28Z")

</div>

Your asgi/wsgi.py file has a statement that is importing the settings module. You can alter the path in this statement to change the settings.py file that is loaded. From there you should be able to import any variables from the settings.py file into other files.

---

<div class="post-metadata">

**Author:** ![mblayman](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mblayman/32/101_2.png) [@mblayman](https://forum.djangoproject.com/u/mblayman)\
**Post date:** [June 15, 2020, 10:28pm UTC](https://forum.djangoproject.com/t/import-custom-variable-inside-different-environment/2978/3 "2020-06-15T22:28:20Z")

</div>

I would avoid changing that value directly in the asgi/wsgi.py files. It’s better to change the environment that controls the settings module. This topic was discussed previously on the forum at [Setting the 'django\_settings\_module' value](https://forum.djangoproject.com/t/setting-the-django-settings-module-value/1661/4). Hopefully that topic provides some clear guidance.

---

<div class="post-metadata">

**Author:** ![Suttonium](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/suttonium/32/1264_2.png) [@Suttonium](https://forum.djangoproject.com/u/Suttonium)\
**Post date:** [June 16, 2020, 3:08pm UTC](https://forum.djangoproject.com/t/import-custom-variable-inside-different-environment/2978/4 "2020-06-16T15:08:05Z")

</div>

That’s smart. Speaking of changing the environment, do you know of a way to implement bash scripts into vscode for use with Django?

---

<div class="post-metadata">

**Author:** ![mblayman](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mblayman/32/101_2.png) [@mblayman](https://forum.djangoproject.com/u/mblayman)\
**Post date:** [June 16, 2020, 3:28pm UTC](https://forum.djangoproject.com/t/import-custom-variable-inside-different-environment/2978/5 "2020-06-16T15:28:12Z")

</div>

I’m sorry, I don’t know too much about VS Code. I used it briefly while playing with Rust, but I mostly stick with Vim.

Outside of code editors, you can use a tool like [django-environ](https://github.com/joke2k/django-environ) to read environment variables from a `.env` file that lives at your repository root. The nice part about this package is that it’s editor agnostic so if you work on a team, then anyone is able to handle environment variables in the same way, regardless of their editor choice.

---

<div class="post-metadata">

**Author:** ![Suttonium](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/suttonium/32/1264_2.png) [@Suttonium](https://forum.djangoproject.com/u/Suttonium)\
**Post date:** [June 16, 2020, 3:56pm UTC](https://forum.djangoproject.com/t/import-custom-variable-inside-different-environment/2978/6 "2020-06-16T15:56:17Z")

</div>

That’s perfect. For production I’ve been using django-decouple with an ini file but I’ll definitely look into using django-environ.

You’re a trooper for using Vim. I use it at work, but I use VSCode at home for my personal django projects.
