doctorsherlock
doctorsherlock

Reputation: 1374

Update sensitive code on Github and server?

I am new to web development and git. I have created a project which i have hosted on pythonanywhere.com. I pushed my code to github and then cloned it to pythonanywhere. I have some information in my settings.py file which i want to hide on github. So how can i make changes to the project on my local machine and update it on github and from there to pythonanywhere without revealing the hidden info.
As i said i am new to using git, so i am unaware of many tools that come with it. What is the proper way to do this?

Upvotes: 3

Views: 123

Answers (1)

dizballanze
dizballanze

Reputation: 1267

Simple solutions is:

  • create settings_local.py near your settings.py
  • move all sensitive stuff to settings_local.py
  • add following code to import sensitive settings to settings.py:

    try:
        from .settings_local import *  # noqa
    except ImportError:
        pass
    
  • add settings_local.py to .gitignore so git would exclude it from commits

  • remove sensitive data from GitHub following this guide
  • create settings_local.py on pythonanywhere and your local machine manually or with some script

Upvotes: 4

Related Questions