“””
Django settings for SH1802Django project.
Generated by ‘django-admin startproject’ using Django 1.11.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
“”“
import os
import sys
Build paths inside the project like this: os.path.join(BASE_DIR, …)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
sys.path.insert(0, os.path.join(BASE_DIR, “apps”))
sys.path.insert(1, os.path.join(BASE_DIR, “extra_apps”))
Quick-start development settings - unsuitable for production
See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ‘8u*v06f&p+(cee#n(+zh=t-ddq23wfn%t4(&!71x#3s2%+w&lx’
SECURITY WARNING: don’t run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
Application definition
INSTALLED_APPS = [
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
]
业务扩展应用注册表
INSTALLED_MYAPPS = [
‘arts_app’,
'xadmin',
'crispy_forms',
'comments',
'message',
'statistic',
'drf_apis',
'rest_framework',
]
INSTALLED_APPS += INSTALLED_MYAPPS
MIDDLEWARE = [
‘django.middleware.security.SecurityMiddleware’,
‘django.contrib.sessions.middleware.SessionMiddleware’,
‘django.middleware.common.CommonMiddleware’,
‘django.middleware.csrf.CsrfViewMiddleware’,
‘django.contrib.auth.middleware.AuthenticationMiddleware’,
‘django.contrib.messages.middleware.MessageMiddleware’,
‘django.middleware.clickjacking.XFrameOptionsMiddleware’,
]
ROOT_URLCONF = ‘SH1802Django.urls’
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’,
],
},
},
]
WSGI_APPLICATION = ‘SH1802Django.wsgi.application’
Database
https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
‘default’: {
# ‘ENGINE’: ‘django.db.backends.sqlite3’,
# ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’),
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘sh_1802_django’,
‘HOST’: ‘10.11.58.76’,
‘PORT’: 3306,
‘USER’: ‘zhougy’,
‘PASSWORD’: ‘123456’,
}
}
Password validation
https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
‘NAME’: ‘django.contrib.auth.password_validation.UserAttributeSimilarityValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.MinimumLengthValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.CommonPasswordValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.NumericPasswordValidator’,
},
]
Internationalization
https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = ‘zh-hans’
TIME_ZONE = ‘Asia/Shanghai’
USE_I18N = True
USE_L10N = True
USE_TZ = False
Static files (CSS, JavaScript, Images)
https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = ‘/static/’
STATICFILES_DIRS=[
os.path.join(BASE_DIR, ‘static’)
]
MEDIA_ROOT = os.path.join(BASE_DIR, “static”)
from django.contrib.messages import constants as message_constants
MESSAGE_LEVEL = message_constants.INFO
SESSION_SERIALIZER = ‘django.contrib.sessions.serializers.PickleSerializer’
SEX_CHOICES = [
(‘M’, ‘男人’),
(‘F’, ‘女人’),
]
USER_CHOICES = [
(0, ‘普通会员’),
(1, ‘VIP会员’),
(2, ‘黄金会员’),
]
DINNER_CHOICES = [
(0, ‘待下单’),
(1, ‘已下单’)
]
PAY_CHOICES = [
(0, ‘货到付款’),
(1, ‘微信支付’),
(2, ‘支付宝支付’),
]
DB_FIELD_VALID_CHOICES = [
(0, ‘未删除’),
(1, ‘已删除’),
]
######## BEGIN
import redis
R = redis.Redis(host=’127.0.0.1’, port=6379, db=1)
######### END
REST_FRAMEWORK = {
# Use Django’s standard django.contrib.auth
permissions,
# or allow read-only access for unauthenticated users.
‘DEFAULT_PERMISSION_CLASSES’: [
‘rest_framework.permissions.IsAdminUser’,
],
‘DEFAULT_PAGINATION_CLASS’: ‘rest_framework.pagination.PageNumberPagination’,
‘PAGE_SIZE’: 1
}
#
Django Logging BEGIN
#
LOGGING_DIR 日志文件存放目录
LOGGING_DIR = “./logs”
if not os.path.exists(LOGGING_DIR):
os.mkdir(LOGGING_DIR)
import logging
LOGGING = {
‘version’: 1,
‘disable_existing_loggers’: False,
‘formatters’: {
‘standard’: {
‘format’: ‘[%(levelname)s][%(asctime)s][%(filename)s][%(funcName)s][%(lineno)d] > %(message)s’
},
‘simple’: {
‘format’: ‘[%(levelname)s]> %(message)s’
},
},
‘filters’: {
‘require_debug_true’: {
‘()’: ‘django.utils.log.RequireDebugTrue’,
},
},
‘handlers’: {
‘console’: {
‘level’: ‘DEBUG’,
‘filters’: [‘require_debug_true’],
‘class’: ‘logging.StreamHandler’,
‘formatter’: ‘simple’
},
‘file_handler’: {
‘level’: ‘INFO’,
‘class’: ‘logging.handlers.TimedRotatingFileHandler’,
‘filename’: ‘%s/django.log’ % LOGGING_DIR,
‘formatter’: ‘standard’
}, # 用于文件输出
‘mail_admins’: {
‘level’: ‘ERROR’,
‘class’: ‘django.utils.log.AdminEmailHandler’,
‘formatter’: ‘standard’
},
},
‘loggers’: {
‘mdjango’: {
‘handlers’: [‘console’, ‘file_handler’],
‘level’: ‘DEBUG’,
‘propagate’: True,
},
‘django.request’: {
‘handlers’: [‘mail_admins’],
‘level’: ‘ERROR’,
‘propagate’: False,
},
}
}
logger = logging.getLogger(“mdjango”)