1. 程式人生 > >Django 配置文件 settings.py

Django 配置文件 settings.py

sta ssa setting templates ges quest bug zone data

1. dubug配置

DEBUG=False

2. 數據庫配置

DATABASES = {
    ‘default‘: {
        ‘ENGINE‘: ‘django.db.backends.mysql‘,
        "NAME": "dbname",
        "USER": "root",
        "PASSWORD": "xxxx",
        "HOST": "192.168.11.166",
        "PORT":3316
    }
}

3. 模板

TEMPLATES = [
    {
        ‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,
        ‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘)]
        ,
        ‘APP_DIRS‘: True,
        ‘OPTIONS‘: {
            ‘context_processors‘: [
                ‘django.template.context_processors.debug‘,
                ‘django.template.context_processors.request‘,
                ‘django.contrib.auth.context_processors.auth‘,
                ‘django.contrib.messages.context_processors.messages‘,
            ],
        },
    },
]

4. 靜態文件

STATIC_URL = ‘/static/‘
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

5. 時區設置

# LANGUAGE_CODE = ‘en-us‘
# TIME_ZONE = ‘UTC‘
LANGUAGE_CODE = ‘zh-hans‘
TIME_ZONE = ‘Asia/Shanghai‘
USE_I18N = True
USE_L10N = True
USE_TZ = False

6. session 配置

# 默認值: 1209600 (2周, 以秒計)
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_AGE = 30 * 60

7. 時間格式設置

DATETIME_FORMAT = ‘Y-m-d H:i:s‘
DATE_FORMAT = ‘Y-m-d‘

Django 配置文件 settings.py