/
ilnar_g
/
111
Обзор
Документация
Войти
/
ilnar_g
/
111
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
settings.py
212 строк
6 KB
ilnar_g
upload files
26 сен 2025, 01:46
26 сен 2025, 01:46
3fd377a
Код
Авторство
О чём код?
""" Django settings for crm_project project. Generated by 'django-admin startproject' using Django 5.2.6. For more information on this file, see https://docs.djangoproject.com/en/5.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.2/ref/settings/ """ import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-ix(_-#7!pfd&54z=7g_!h$y8*y&@aiw+f+^mu6x!^1wt93otzs' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['*'] # На время debugging ALLOWED_HOSTS = [ '81.30.105.148', # IP адрес сервера 'crm.mamadysh.ru', # доменное имя 'www.crm.mamadysh.ru', 'localhost', # локальный хост '127.0.0.1', # локальный IP '0.0.0.0', # все интерфейсы '*', # для разработки (не для production) ] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'counterparties', 'corsheaders', # ← ДОБАВЛЕНО ] MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', # ← ДОБАВЛЕНО ПЕРВЫМ! '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 = 'crm_project.urls' # Настройки аутентификации LOGIN_URL = '/accounts/login/' LOGIN_REDIRECT_URL = '/' LOGOUT_REDIRECT_URL = '/' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['/var/www/fastuser/data/www/crm.mamadysh.ru/templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'crm_project.wsgi.application' # Database # https://docs.djangoproject.com/en/5.2/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'crm_db', 'USER': 'crm_user', 'PASSWORD': 'w?Ux;b*ov{;oRv`P', 'HOST': 'localhost', 'PORT': '3306', 'OPTIONS': { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", 'charset': 'utf8mb4', }, } } # Password validation # https://docs.djangoproject.com/en/5.2/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/5.2/topics/i18n/ LANGUAGE_CODE = 'ru-ru' TIME_ZONE = 'Europe/Moscow' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.2/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = '/var/www/fastuser/data/www/crm.mamadysh.ru/static/' # Default primary key field type # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field # Настройки CSRF для работы за прокси CSRF_COOKIE_SECURE = True CSRF_COOKIE_HTTPONLY = True CSRF_TRUSTED_ORIGINS = [ 'https://crm.mamadysh.ru', 'https://www.crm.mamadysh.ru', 'http://crm.mamadysh.ru', 'http://www.crm.mamadysh.ru', ] DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' # Настройки сессий SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True # Настройки для прокси SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') USE_X_FORWARDED_HOST = True USE_X_FORWARDED_PORT = True # Telegram notifications settings TELEGRAM_BOT_TOKEN = '8237985314:AAFLse5T6FBXFYDfhVHp8rJbf-juOM16kBM' # Замените на реальный токен TELEGRAM_CHAT_ID = '352916501' # Замените на реальный chat_id TELEGRAM_API_URL = f'https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}' # CORS settings for API access from reklama.mamadysh.ru CORS_ALLOWED_ORIGINS = [ "https://reklama.mamadysh.ru", "http://reklama.mamadysh.ru", "https://www.reklama.mamadysh.ru", "http://www.reklama.mamadysh.ru", "http://localhost:8000", "http://127.0.0.1:8000", ] CORS_ALLOW_CREDENTIALS = True CORS_ALLOW_ALL_ORIGINS = False # Важно: False для продакшена! # Дополнительные настройки CORS CORS_ALLOW_METHODS = [ 'DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT', ] CORS_ALLOW_HEADERS = [ 'accept', 'accept-encoding', 'authorization', 'content-type', 'dnt', 'origin', 'user-agent', 'x-csrftoken', 'x-requested-with', ] REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.TokenAuthentication', ] } # Для API отключаем CSRF проверку CSRF_USE_SESSIONS = False