I’m new to Python and Django and have over the past few weeks managed to set up my first deployment – a very basic site with user authentication and a few pages, which I hope to fill with content in the next couple of weeks.
I have managed to find the answer to probably 40+ questions I have encountered so far by searching Google / StackOverflow / Django docs etc., but now I have one I can’t seem to find a good answer to (perhaps because I don’t know how best to search for it): when I develop on my local machine I need my settings.py file to point to the remote database ('HOST': 'www.mysite.com',) but when I deploy to a shared hosting service provider they require the use of localhost ('HOST': '', in settings.py).
Since I host my code on GitHub and want to mirror it to the server, is there a way to resolve this so I don’t have to make a manual edit to settings.py each time after uploading changes to the server?
You can have two copies of your
settings.pyfile, one for production and one for development. Whatever you need to be the default, name it assettings.pyJust set
DJANGO_SETTINGS_MODULEto the python path for the file that you would like to use.So, if your settings files are
myproject/settings.py, myproject/settings_dev.py; you can then do:$ DJANGO_SETTINGS_MODULE=settings_dev python manage.py shellFrom the
myprojectdirectory.