Mercurial: exclude django settings.py after intitial commit

In my Django project, I want the settings.py file to be included in the initial commit so that other developers can clone the repository and change the initial settings to work with local settings. But after that, I don’t want to manually exclude the file at each commit, and the ignore file does not work, because it is already being tracked.

So, how can I get mercurial to automatically exclude settings.py when saving the original file?

Appreciate any help :)

+3
source share
3 answers

There is an alternative, perhaps more flexible approach to this. Do not exclude the file settings.py.

Instead, do the following:

try:
  from localsettings import *
except ImportError:
  pass

, - settings.py, . , , , localsettings.

localsettings.py , ( DEBUG, , , ).

, localsettings.py .

+9

Mercurual - , - settings.py.template, , - , settings.py, .hgignore. , - , . / script -, .

+2

, , , . ( , ).

settings.py , .

An example is a database connection, which often differs from one computer to another:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',  
        'NAME': os.environ['DB_NAME'],                      
        'USER': os.environ['DB_USER'],
        'PASSWORD': os.environ['DB_PASSWORD'],
        'HOST': os.environ['DB_HOST'],                      
        'PORT': os.environ['DB_PORT'],                      
    } }
0
source

Source: https://habr.com/ru/post/1787117/


All Articles