Home > Back-end >  When I add settings folder with settings for different environments, I get CommandError: You must se
When I add settings folder with settings for different environments, I get CommandError: You must se

Time:10-26

I want to make two files with different settings for dev and prod.

I created a python package in the app folder where my settings are, and even if I run the app with old settings, I receive an error:

CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

Here is my project structure: enter image description here

CodePudding user response:

Well at first for this purpose:

I want to make two files with different settings for dev and prod.

You should move to settings.py module to settings dir at first and it's better to change its name to for example base.py. After that, you can provide two modules called dev.py and prod.py for a different modes of your projects.

Also with these changes, you must change the route of your settings in manage.py module.

Note: with these changes, you can provide different values for DEBUG, ALLOWED_HOSTS, etc. in your different modes.

CodePudding user response:

The problem was that I should specify the path to my settings in my run settings: enter image description here

Also, in I should change my BASE_DIR by adding one more parent here:

BASE_DIR = Path(__file__).resolve().parent.parent.parent
  • Related