0

I am writing a Django project that it needs to be divided as production/development, but however my project looks like this, how can I organize in order to execute python manage.py runserver for dev or prod.

.
├── apps
│   ├── account
│   │   ├── migrations
│   │   │   └── __pycache__
│   │   └── __pycache__
│   ├── course
│   │   ├── migrations
│   │   └── __pycache__
│   ├── quizgame
│   │   ├── migrations
│   │   │   └── __pycache__
│   │   └── __pycache__
│   └── site
│       └── __pycache__
└── app
    └── __pycache__

16 directories

1 Answers1

0

As I remember, settings.py must be inside app directory. So, you need to create new directory inside app, for example with name settings. Then you need to modify manage.py and set the next code:

os.environ.setdefault('DJANGO_SETTINGS_MODULE', '<root_folder_name>.app.settings')

Then, you can create two new files dev_settings.py and prod_settings.py in settings folder.

Now, you can run code with other settings, but you need to add parameter --settings=settings.dev_settings to all your management commands, for example:

python manage.py runserver --settings=settings.dev_settings

or

python manage.py migrate --settings=settings.prod_settings

I hope, I helped you.

  • You don't have to have the `settings.py` inside an app folder. You would need to modify the `wsgi.py` file and `manage.py` file to point to where ever the `settings.py` file is. This works no matter if you are running in a development environment or production environment. – ja408 Apr 07 '20 at 06:24