django的local_settings.py的用法

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/brytlevson/article/details/102384152

在git上面下载下来的代码,settings.py中肯定是不全的,包括数据库的配置,静态资源的路径等。通过在settings.py中import local_settings.py来实现对默认设置的覆盖,这样可以实现在不同的机器上,通过设置不同的local_settings.py的内容,来方便开发和部署。在settings.py的末尾添加下面几行:

try:
from local_settings import *
except ImportError:
pass

这样的话setting里面有异常的话,local_settings.py会覆盖掉settings里面的配置。

我做的GIS系统;所以加的东西有点多;
而且git提交local_settings.py不会提交的;

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DEBUG = True

ALLOWED_HOSTS = ['*']

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'xxxxxxxxxxxx',
        'USER': 'xxxxxxxxxxxx',
        'PASSWORD': '888888',
        'HOST': '210.72.90.2',
        'PORT': '5432',
    }
}


if os.name == 'nt':
    import platform
    OSGEO4W = r"E:\Install Programes\QGIS 3.8"
    # if '64' in platform.architecture()[0]:
    #     OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
    os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']


STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]
STATIC_URL = '/static/'
MEDIA_URL = '/static/upload/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/upload/')

猜你喜欢

转载自blog.csdn.net/brytlevson/article/details/102384152