6
0

settings.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. """
  2. Django settings for config project.
  3. Generated by 'django-admin startproject' using Django 4.0.4.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/4.0/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/4.0/ref/settings/
  8. """
  9. from pathlib import Path
  10. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  11. BASE_DIR = Path(__file__).resolve().parent.parent
  12. # Quick-start development settings - unsuitable for production
  13. # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = 'django-insecure-@(1d9p3fp!%78l3)x_ejy28n)^_jvwm-)sd3g6+t1l8cjh6gh+'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = True
  18. ALLOWED_HOSTS = []
  19. # Application definition
  20. INSTALLED_APPS = [
  21. # User apps
  22. 'users',
  23. # Django apps
  24. 'django.contrib.admin',
  25. 'django.contrib.auth',
  26. 'django.contrib.contenttypes',
  27. 'django.contrib.sessions',
  28. 'django.contrib.messages',
  29. 'django.contrib.staticfiles',
  30. 'django.contrib.sites', #required for allauth
  31. # Allauth apps
  32. 'allauth',
  33. 'allauth.account',
  34. 'allauth.socialaccount',
  35. 'allauth.socialaccount.providers.google',
  36. # Other apps
  37. 'phonenumber_field',
  38. ]
  39. MIDDLEWARE = [
  40. 'django.middleware.security.SecurityMiddleware',
  41. 'django.contrib.sessions.middleware.SessionMiddleware',
  42. 'django.middleware.common.CommonMiddleware',
  43. 'django.middleware.csrf.CsrfViewMiddleware',
  44. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  45. 'django.contrib.messages.middleware.MessageMiddleware',
  46. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  47. ]
  48. ROOT_URLCONF = 'config.urls'
  49. TEMPLATES = [
  50. {
  51. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  52. 'DIRS': [],
  53. 'APP_DIRS': True,
  54. 'OPTIONS': {
  55. 'context_processors': [
  56. 'django.template.context_processors.debug',
  57. 'django.template.context_processors.request',
  58. 'django.contrib.auth.context_processors.auth',
  59. 'django.contrib.messages.context_processors.messages',
  60. ],
  61. },
  62. },
  63. ]
  64. WSGI_APPLICATION = 'config.wsgi.application'
  65. # Database
  66. # https://docs.djangoproject.com/en/4.0/ref/settings/#databases
  67. '''
  68. # Чтобы посмотреть на работу, не подключая postgres, закомментируйте словарь
  69. # DATABASE под комментарием и раскомментируйте тот же словарь в комментарии,
  70. # а затем используйте команды:
  71. # $ python manage.py makemigrations
  72. # $ python manage.py migrate
  73. #
  74. # Cоздатся sqlite3 БД в корневой папке, и проект будет работать на нём.
  75. DATABASES = {
  76. 'default': {
  77. 'ENGINE': 'django.db.backends.sqlite3',
  78. 'NAME': BASE_DIR / 'db.sqlite3',
  79. }
  80. }
  81. '''
  82. DATABASES = {
  83. 'default': {
  84. 'ENGINE': 'django.db.backends.postgresql',
  85. 'NAME': 'auth',
  86. 'USER': 'postgres',
  87. 'PASSWORD': 'admin',
  88. 'HOST': 'localhost',
  89. 'PORT': '5432',
  90. }
  91. }
  92. # Password validation
  93. # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
  94. AUTH_PASSWORD_VALIDATORS = [
  95. {
  96. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  97. },
  98. {
  99. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  100. },
  101. {
  102. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  103. },
  104. {
  105. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  106. },
  107. ]
  108. # Internationalization
  109. # https://docs.djangoproject.com/en/4.0/topics/i18n/
  110. LANGUAGE_CODE = 'en-us'
  111. TIME_ZONE = 'UTC'
  112. USE_I18N = True
  113. USE_TZ = True
  114. # Static files (CSS, JavaScript, Images)
  115. # https://docs.djangoproject.com/en/4.0/howto/static-files/
  116. STATIC_URL = 'static/'
  117. STATIC_ROOT = BASE_DIR / 'production/static'
  118. #if static files are located in several dirs
  119. STATICFILES_DIRS = [
  120. BASE_DIR / "static",
  121. #("css", "/opt/webfiles/stats"),
  122. ]
  123. # Default primary key field type
  124. # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
  125. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  126. AUTH_USER_MODEL = 'users.User'
  127. # Allauth settings
  128. SITE_ID = 1 #required by django.contrib.sites
  129. AUTHENTICATION_BACKENDS = [
  130. # Needed to login by username in Django admin, regardless of `allauth`
  131. 'django.contrib.auth.backends.ModelBackend',
  132. # `allauth` specific authentication methods, such as login by e-mail
  133. 'allauth.account.auth_backends.AuthenticationBackend',
  134. # Custom backend, authenticate with phone number
  135. 'users.backends.CustomAuthenticationBackend',
  136. ]
  137. ACCOUNT_FORMS = {
  138. 'login': 'users.forms.CustomLoginForm',
  139. 'signup': 'users.forms.SignupForm',
  140. 'add_email': 'allauth.account.forms.AddEmailForm',
  141. 'change_password': 'allauth.account.forms.ChangePasswordForm',
  142. 'set_password': 'allauth.account.forms.SetPasswordForm',
  143. 'reset_password': 'allauth.account.forms.ResetPasswordForm',
  144. 'reset_password_from_key': 'allauth.account.forms.ResetPasswordKeyForm',
  145. 'disconnect': 'allauth.socialaccount.forms.DisconnectForm',
  146. }
  147. ACCOUNT_USER_MODEL_USERNAME_FIELD = None
  148. ACCOUNT_EMAIL_REQUIRED = True
  149. ACCOUNT_USERNAME_REQUIRED = False
  150. ACCOUNT_AUTHENTICATION_METHOD = 'email'
  151. ACCOUNT_ADAPTER = 'users.adapter.CustomAccountAdapter'
  152. ACCOUNT_SESSION_REMEMBER = True #Remember me checkbox
  153. LOGIN_REDIRECT_URL = 'users:profile'
  154. EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
  155. # Phone number field settings
  156. PHONENUMBER_DEFAULT_REGION = 'RU'