settings.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. # coding=utf-8
  2. """
  3. Django settings for cosmetics_shop project.
  4. Generated by 'django-admin startproject' using Django 1.9.13.
  5. For more information on this file, see
  6. https://docs.djangoproject.com/en/1.9/topics/settings/
  7. For the full list of settings and their values, see
  8. https://docs.djangoproject.com/en/1.9/ref/settings/
  9. """
  10. import os, datetime
  11. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  12. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  13. # Quick-start development settings - unsuitable for production
  14. # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
  15. # SECURITY WARNING: keep the secret key used in production secret!
  16. SECRET_KEY = '%domhs7p_)nl&c-$@al(xsk+u^y*qezl!m@l_k72)3n+%ct$z5'
  17. # SECURITY WARNING: don't run with debug turned on in production!
  18. DEBUG = True
  19. ALLOWED_HOSTS = ['*']
  20. # Application definition
  21. INSTALLED_APPS = [
  22. # 'django.contrib.admin',
  23. 'django.contrib.auth',
  24. 'django.contrib.contenttypes',
  25. 'django.contrib.sessions',
  26. 'django.contrib.messages',
  27. 'django.contrib.staticfiles',
  28. 'corsheaders',
  29. 'rest_framework',
  30. 'rest_framework_jwt',
  31. 'django_filters',
  32. 'apps.account',
  33. 'apps.api',
  34. 'apps.collection',
  35. 'apps.commodity',
  36. 'apps.config',
  37. 'apps.customer',
  38. 'apps.dashboard',
  39. 'apps.employee',
  40. 'apps.images',
  41. 'apps.log',
  42. 'apps.option',
  43. 'apps.order',
  44. 'apps.rebate',
  45. 'apps.WechatApplet',
  46. ]
  47. MIDDLEWARE = [
  48. 'django.middleware.security.SecurityMiddleware',
  49. 'django.contrib.sessions.middleware.SessionMiddleware',
  50. 'django.middleware.common.CommonMiddleware',
  51. 'django.middleware.csrf.CsrfViewMiddleware',
  52. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  53. 'django.contrib.messages.middleware.MessageMiddleware',
  54. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  55. 'corsheaders.middleware.CorsMiddleware',
  56. ]
  57. CORS_ALLOW_CREDENTIALS = True # 允许携带cookie
  58. CORS_ORIGIN_ALLOW_ALL = True
  59. CORS_ALLOW_METHODS = (
  60. 'DELETE',
  61. 'GET',
  62. 'OPTIONS',
  63. 'PATCH',
  64. 'POST',
  65. 'PUT',
  66. 'VIEW',
  67. )
  68. CORS_ALLOW_HEADERS = (
  69. 'XMLHttpRequest',
  70. 'X_FILENAME',
  71. 'accept-encoding',
  72. 'authorization',
  73. 'content-type',
  74. 'dnt',
  75. 'origin',
  76. 'token',
  77. 'user-agent',
  78. 'x-csrftoken',
  79. 'x-requested-with',
  80. 'Pragma',
  81. )
  82. ROOT_URLCONF = 'cosmetics_shop.urls'
  83. AUTH_USER_MODEL = "account.User"
  84. AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.AllowAllUsersModelBackend']
  85. TEMPLATES = [
  86. {
  87. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  88. 'DIRS': [],
  89. 'APP_DIRS': True,
  90. 'OPTIONS': {
  91. 'context_processors': [
  92. 'django.template.context_processors.debug',
  93. 'django.template.context_processors.request',
  94. 'django.contrib.auth.context_processors.auth',
  95. 'django.contrib.messages.context_processors.messages',
  96. ],
  97. },
  98. },
  99. ]
  100. WSGI_APPLICATION = 'cosmetics_shop.wsgi.application'
  101. # Database
  102. # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
  103. DATABASES = {
  104. 'default': {
  105. 'ENGINE': 'django.db.backends.mysql',
  106. 'NAME': 'cosmetics_shop',
  107. 'USER': 'carwin',
  108. 'PASSWORD': 'carwin!@#',
  109. 'HOST': '192.168.2.55',
  110. 'PORT': 3306,
  111. }
  112. }
  113. # Password validation
  114. # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
  115. AUTH_PASSWORD_VALIDATORS = [
  116. {
  117. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  118. },
  119. {
  120. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  121. },
  122. {
  123. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  124. },
  125. {
  126. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  127. },
  128. ]
  129. # Internationalization
  130. # https://docs.djangoproject.com/en/1.9/topics/i18n/
  131. LANGUAGE_CODE = 'zh-hans'
  132. TIME_ZONE = 'Asia/Shanghai'
  133. USE_I18N = True
  134. USE_L10N = True
  135. USE_TZ = False
  136. # Static files (CSS, JavaScript, Images)
  137. # https://docs.djangoproject.com/en/1.9/howto/static-files/
  138. STATIC_URL = '/static/'
  139. STATIC_ROOT = os.path.join(BASE_DIR, "uis/static/")
  140. STATICFILES_DIRS = (
  141. os.path.join(BASE_DIR, "static"),
  142. )
  143. MEDIA_URL = '/up/'
  144. MEDIA_ROOT = os.path.join(BASE_DIR, "uis/up/")
  145. UIS_URL = '/'
  146. UIS_ROOT = os.path.join(BASE_DIR, "uis/")
  147. SERVER_DOMAIN = 'http://192.168.2.164:8089'
  148. JWT_AUTH = {
  149. 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=30),
  150. 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=360),
  151. 'JWT_ALLOW_REFRESH': True,
  152. }
  153. REST_FRAMEWORK = {
  154. 'DEFAULT_PERMISSION_CLASSES': (
  155. 'rest_framework.permissions.AllowAny',
  156. ),
  157. 'DEFAULT_AUTHENTICATION_CLASSES': (
  158. 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
  159. #'rest_framework.authentication.SessionAuthentication',
  160. #'rest_framework.authentication.BasicAuthentication',
  161. ),
  162. 'DEFAULT_PARSER_CLASSES': (
  163. 'rest_framework.parsers.JSONParser',
  164. 'rest_framework.parsers.FormParser',
  165. 'rest_framework.parsers.MultiPartParser'
  166. ),
  167. 'DEFAULT_RENDERER_CLASSES': (
  168. 'rest_framework.renderers.JSONRenderer',
  169. # 'rest_framework.renderers.BrowsableAPIRenderer',
  170. ),
  171. 'DEFAULT_FILTER_BACKENDS': (
  172. 'django_filters.rest_framework.DjangoFilterBackend',
  173. ),
  174. # 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
  175. 'DEFAULT_PAGINATION_CLASS': 'utils.pagination.CustomPagination',
  176. # 'EXCEPTION_HANDLER': 'rest_framework.views.exception_handler',
  177. 'EXCEPTION_HANDLER': 'utils.handler.custom_exception_handler',
  178. 'PAGE_SIZE': 10,
  179. 'DATETIME_FORMAT': "%Y-%m-%d %H:%M:%S",
  180. 'NON_FIELD_ERRORS_KEY': "error", # 序列化器错误KEY名称
  181. }
  182. # 导入本地设置
  183. try:
  184. from cosmetics_shop.local_settings import *
  185. except ImportError:
  186. pass
  187. UNKNOWN = 0
  188. MALE = 1
  189. FEMALE = 2
  190. GENDER_CHOICES = (
  191. (UNKNOWN, u'未知'),
  192. (MALE, u'男'),
  193. (FEMALE, u'女'),
  194. )
  195. OFFLINE = 0
  196. ONLINE = 1
  197. SALES_STATUS_CHOICES = (
  198. (OFFLINE, u'下架'),
  199. (ONLINE, u'上架'),
  200. )