settings copy.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import os,sys
  2. from datetime import timedelta
  3. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  4. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  5. PROJECT_ROOT = os.path.dirname(__file__)
  6. sys.path.insert(0,os.path.join(PROJECT_ROOT,'apps'))
  7. AUTH_USER_MODEL = 'authAPI.CustomUser'
  8. try:
  9. if os.environ['debug'] == 'False':
  10. DEBUG = False
  11. else:
  12. DEBUG = True
  13. except:
  14. DEBUG = True
  15. if DEBUG:
  16. SECRET_KEY = 'django-insecure-e*vqkvk_c%y&(v-^isb_%uwxq#y4eun3xhf4al_5f_)&14e5f0'
  17. else:
  18. try:
  19. SECRET_KEY = os.environ["SECRET_KEY"]
  20. except KeyError as e:
  21. raise RuntimeError("Could not find a SECRET_KEY in environment") from e
  22. from .prod import *
  23. # Application definition
  24. INSTALLED_APPS = [
  25. 'django.contrib.admin',
  26. 'django.contrib.auth',
  27. 'django.contrib.contenttypes',
  28. 'django.contrib.sessions',
  29. 'django.contrib.messages',
  30. 'django.contrib.staticfiles',
  31. 'rest_framework',
  32. 'goods.apps.GoodsConfig',
  33. 'authAPI.apps.AuthAPIConfig',
  34. 'orders.apps.OrdersConfig',
  35. 'categories.apps.CategoriesConfig',
  36. ]
  37. MIDDLEWARE = [
  38. 'django.middleware.security.SecurityMiddleware',
  39. 'django.contrib.sessions.middleware.SessionMiddleware',
  40. 'django.middleware.common.CommonMiddleware',
  41. 'django.middleware.csrf.CsrfViewMiddleware',
  42. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  43. 'django.contrib.messages.middleware.MessageMiddleware',
  44. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  45. ]
  46. ROOT_URLCONF = 'store_back.urls'
  47. TEMPLATES = [
  48. {
  49. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  50. 'DIRS': [],
  51. 'APP_DIRS': True,
  52. 'OPTIONS': {
  53. 'context_processors': [
  54. 'django.template.context_processors.debug',
  55. 'django.template.context_processors.request',
  56. 'django.contrib.auth.context_processors.auth',
  57. 'django.contrib.messages.context_processors.messages',
  58. ],
  59. },
  60. },
  61. ]
  62. WSGI_APPLICATION = 'store_back.wsgi.application'
  63. AUTH_PASSWORD_VALIDATORS = [
  64. {
  65. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  66. },
  67. {
  68. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  69. },
  70. {
  71. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  72. },
  73. {
  74. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  75. },
  76. ]
  77. # Internationalization
  78. # https://docs.djangoproject.com/en/4.0/topics/i18n/
  79. LANGUAGE_CODE = 'en-us'
  80. TIME_ZONE = 'UTC'
  81. USE_I18N = True
  82. USE_TZ = True
  83. DATABASES = {
  84. 'default': {
  85. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  86. 'NAME': 'dfi11snf6cpamj',
  87. 'USER' : 'qvkowaptdjfexz',
  88. 'PASSWORD' : '3ef6f3a16c918da406cd2b388042a45080ff7f9dd10d5f9cc1df0ec0eca8ab7a',
  89. 'HOST' : 'ec2-52-48-159-67.eu-west-1.compute.amazonaws.com',
  90. 'PORT' : '5432',
  91. }
  92. }
  93. # Static files (CSS, JavaScript, Images)
  94. # https://docs.djangoproject.com/en/4.0/howto/static-files/
  95. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  96. STATIC_URL = 'api/static/'
  97. MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/')
  98. MEDIA_URL = 'api/media/'
  99. # Default primary key field type
  100. # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
  101. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  102. SIMPLE_JWT = {
  103. 'ACCESS_TOKEN_LIFETIME': timedelta(days=30),
  104. 'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
  105. 'ROTATE_REFRESH_TOKENS': False,
  106. 'BLACKLIST_AFTER_ROTATION': False,
  107. 'UPDATE_LAST_LOGIN': False,
  108. 'ALGORITHM': 'HS256',
  109. 'SIGNING_KEY': SECRET_KEY,
  110. 'VERIFYING_KEY': None,
  111. 'AUDIENCE': None,
  112. 'ISSUER': None,
  113. 'JWK_URL': None,
  114. 'LEEWAY': 0,
  115. 'AUTH_HEADER_TYPES': ('Bearer',),
  116. 'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
  117. 'USER_ID_FIELD': '_id',
  118. 'USER_ID_CLAIM': 'user_id',
  119. 'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule',
  120. 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
  121. 'TOKEN_TYPE_CLAIM': 'token_type',
  122. 'TOKEN_USER_CLASS': 'rest_framework_simplejwt.models.TokenUser',
  123. 'JTI_CLAIM': 'jti',
  124. 'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
  125. 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
  126. 'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
  127. }
  128. REST_FRAMEWORK = {
  129. 'DEFAULT_AUTHENTICATION_CLASSES': (
  130. 'rest_framework_simplejwt.authentication.JWTAuthentication',
  131. )
  132. }