Home > Software design >  Django - separating prod and dev settings - delete original settings.py?
Django - separating prod and dev settings - delete original settings.py?

Time:09-23

I'm following the below answer on separating development and production Django settings file.

https://stackoverflow.com/a/54292952/15166930

  1. After separating, would I delete the original settings.py file?

  2. Is this the common practice on separating the files? I see multiple methods on that SO post.

  3. Also, per the SO answer, I'm to update the BASE_DIR in my base.py file to

BASE_DIR = Path(file).resolve().parent.parent.parent

right now it's as below:

settings.py
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Just want to confirm because the two are so different.. thx (Django 2.1.7)

CodePudding user response:

There are a number of methods for having different settings in development and production.

If you choose to follow the method you have linked, then yes, you would remove your original settings.py file and replace it with a settings directory that contains base.py, dev.py and prod.py; with base.py containing the common settings and the other files containing the contextual settings (whether you are either in development or production).

Also, is there a critical reason you are using Django 2.1.7? It has a number of known vulnerabilities.

CodePudding user response:

You can use different settings using the dotenv library, you create .env file from where you pull your settings.

Another solution is to have a settings_local.py file from where you pull your settings as well, and adjusting it according to your environment.

Edit : I agree with the first answer stating that using django 2 today is a bad idea, many many things changed since then and if you really want to follow a tutorial, I'd recommend something more up to date, like William S. Vincent books, "Django for Beginners: Build websites with Python and Django", there are 4.X books already. I highly recommend his books for beginners, as it takes a good project oriented approach.

  • Related