I have a basic django rest API. I want to separate some of my settings for dev and prod just for organizational purposes. I'm also just learning about separating environments. I've read a few things, but I can't seem to get it working the way I want it to.
The hierarchy looks like this:
- djangorest
- api
- __init__.py
- models.py
- views.py
- urls.py
- etc..
- djangorest
- __init__.py
- settings.py
- urls.py
- wsgi.py
Right now, when I run the server, I do a simple:
python3 manage.py runserver
That command reads the settings from settings.py and runs it appropriately but I've looked around on how to separate the settings into prod vs dev and it doesn't work right.
I want to be able to have:
commonsettings.py
dev.py
prod.py
In commonsettings, it'll just have whatever's in both dev and prod. I've tried running:
python3 manage.py runserver --settings=settings.dev
But it gives me an error saying there is no module named 'setting'.
Please help. Thank you!
How do I run Python py Runserver on different ports? If you want to use a different port than the default 8000, specify the port number on the command line, such as python manage.py runserver 5000 . Ctrl+click the http://127.0.0.1:8000/ URL in the terminal output window to open your default browser to that address.
For example I open SQL log in dev settings
My file structure:
create settings folder and mv original settings.py to settings/defaults.py
load defaults in init.py
# proj/proj/settings/__init__.py
from .defaults import *
# proj/proj/settings/dev.py
from .defaults import *
DEBUG = True
# print sql to the console
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
}
},
'loggers': {
'django.db.backends': {
'handlers': ['console'],
'propagate': True,
'level': 'DEBUG',
}
},
}
./manage.py runserver --settings proj.settings.dev
Django 2.1.7 | Mac
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With