"""
Django settings for myplatform project.
Generated by 'django-admin startproject' using Django 2.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
import djcelery
import sys
djcelery.setup_loader()
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Project_URL = r'E:\myplatform\project'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#60ynqd#2^ew3=ld3l)m94#!8$tx-n@dro$x8z^*(u8@kt7^@9'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*',]
# BROKER_URL = 'redis://localhost:6379/0'
BROKER_URL = 'amqp://jietong:jietong@10.0.2.111:5672//'
# sys.path.insert(0, os.getcwd())
# CELERY_IMPORTS = ("tasks", )
# CELERY_RESULT_BACKEND = "amqp"
# BROKER_HOST = "localhost"
# BROKER_PORT = 5672
# BROKER_USER = "guest"
# BROKER_PASSWORD = "guest"
# BROKER_VHOST = "/"
CELERY_RESULT_BACKEND='redis://localhost:6379/1'
# CELERY_ACCEPT_CONTENT=['application/json',]
CELERY_ACCEPT_CONTENT=['pickle','json']#任务的接收格式
CELERT_TASK_SERIALIZER='json' #序列化成的格式
CELERT_RESULT_SERIALIZER='json' #反序列化
CELERYD_CONCURRENCY = 20 # 并发worker数
CELERYD_MAX_TASKS_PER_CHILD = 100 # 每个worker最多执行万100个任务就会被销毁,可防止内存泄露
CELERYD_FORCE_EXECV = True # 非常重要,有些情况下可以防止死锁
CELERY_CREATE_MISSING_QUEUES = True
CELERY_TASK_RESULT_EXPIRES = 10 # 防止任务过期
CELERY_DISABLE_RATE_LIMITS = True # 任务发出后,经过一段时间还未收到acknowledge , 就将任务重新交给其他worker执行
# Application definition
WEBSOCKET_FACTORY_CLASS = 'dwebsocket.backends.uwsgi.factory.uWsgiWebSocketFactory'
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_crontab',
'user',
'dwebsocket',
'project',
'category',
]
MIDDLEWARE = [
'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 = 'myplatform.urls'
WEBSOCKET_ACCEPT_ALL=True #websocket协议
CRONJOBS = [
('23 * * * *','project.views.time_package_recycle'),
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [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 = 'myplatform.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'new_data',
'USER': 'yuanchaoyi',
'PASSWORD': 'jietong123',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
'autocommit': True,
},
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/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',
},
]
# CELERY_IMPORTS=(
# "project.tasks",
# )
# CELERT_QUEUES =(
# Queue("celery",Exchange("celery"),routing_key="celery"),
# Queue("for_task_A", Exchange("for_task_A"),routing_key="task_a"),
# Queue("for_task_B", Exchange("for_task_B"), routing_key="task_b"),
# )
# CELERY_DEFAULT_QUEUE = 'default'
# CELERY_DEFAULT_EXCHANGE = 'default'
# CELERY_DEFAULT_ROUTTING_KEY = 'default'
# CELERY_ROUTES = {
# 'project.tasks.upload':{"queue":"for_task_A","routing_key":"task_a"},
# 'project.tasks.upload':{"queue":"celery","routing_key":"celery"},
# 'tasks.taskB':{"queue":"for_task_B","routing_key":"task_b"}
# }
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = '/root/var/www/myplatform/static'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "common_static"),
)
MEDIA_ROOT = os.path.join(BASE_DIR,'media').replace('\\','/')
MEDIA_URL = '/meida/'