""" Django settings for mosqkiller project. Generated by 'django-admin startproject' using Django 2.0.5. For more information on this file, see https://docs.djangoproject.com/en/2.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.0/ref/settings/ """ import os import sys import datetime from celery.schedules import crontab # 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')) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'l_npcm8lc26$c#o5p!1j+$^@99lpv)l6+4lyc*2(+h8t_phwx%' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['iot.celex.cn', '47.106.73.20', '127.0.0.1', 'mosq.celex-iot.com'] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'django_filters', 'corsheaders', 'accounts', 'mosquito', 'smart', 'counter', 'django_celery_results', ] 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', ] CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_HEADERS = [ 'X-Token', 'Content-Type', 'Authorization', ] ROOT_URLCONF = 'mosqkiller.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 = 'mosqkiller.wsgi.application' # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'mosqkiller', 'USER': 'mosq_admin', 'PASSWORD': 'Q5BkPk62mqeBxI_lHh2', 'HOST': '47.106.73.20', 'PORT': 3326, 'OPTIONS': {'init_command': 'SET sql_mode="STRICT_TRANS_TABLES"'} }, 'counter': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'counter', 'USER': 'mosq_admin', 'PASSWORD': 'Q5BkPk62mqeBxI_lHh2', 'HOST': '47.106.73.20', 'PORT': 3316 } } DATABASE_APPS_MAPPING = { 'counter': 'counter' } DATABASE_ROUTERS = ['mosqkiller.database_router.DatabaseAppsRouter'] # Password validation # https://docs.djangoproject.com/en/2.0/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', }, ] AUTH_USER_MODEL = 'accounts.User' # Internationalization # https://docs.djangoproject.com/en/2.0/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.0/howto/static-files/ STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ] # STATIC_ROOT = os.path.join(BASE_DIR, 'static') # drf settings REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': ( 'rest_framework.renderers.JSONRenderer', 'rest_framework.renderers.BrowsableAPIRenderer', ), 'DEFAULT_PARSER_CLASSES': ( 'rest_framework.parsers.JSONParser', ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', 'rest_framework.authentication.SessionAuthentication', # 'rest_framework.authentication.BasicAuthentication' ), 'DEFAULT_PERMISSION_CLASSES': ( # 'rest_framework.permissions.IsAuthenticatedOrReadOnly', 'rest_framework.permissions.IsAuthenticated', ) } JWT_AUTH = { 'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=3600), } # Custom auth backend # AUTHENTICATION_BACKENDS = ( # 'accounts.api.views.CustomBackend', # ) # CACHES CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://:IySpkVL39NeOgyC@47.106.73.20:6389/1", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } } } # Celery settings CELERY_BROKER_URL = 'redis://:IySpkVL39NeOgyC@127.0.0.1:6379/2' CELERY_RESULT_BACKEND = 'django-db' CELERY_ACCEPT_CONTENT = ['json'] CELERY_TASK_SERIALIZER = 'json' CELERY_TIMEZONE = 'Asia/Shanghai' CELERY_BEAT_SCHEDULE = { 'update-daily-statistic': { 'task': 'mosquito.tasks.update_daily_statistic', 'schedule': crontab(minute="*/30"), }, 'update-mosq-device-info': { 'task': 'mosquito.tasks.update_mosq_device_info', 'schedule': crontab(minute="*/5"), }, # 'update-latest-statistic': { # 'task': 'mosquito.tasks.update_mosql_device_location', # 'schedule': crontab(hour='*/2', minute=0), # }, } # logging db query # LOGGING = { # 'version': 1, # 'disable_existing_loggers': False, # 'handlers': { # 'console': { # 'class': 'logging.StreamHandler', # }, # }, # 'loggers': { # 'django.db.backends': { # 'handlers': ['console'], # 'level': 'DEBUG' if DEBUG else 'INFO', # }, # }, # }