diagnose-backend/educheck/settings.py
2025-03-01 00:26:39 +08:00

190 lines
5.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Django settings for educheck project.
Generated by 'django-admin startproject' using Django 4.2.19.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
from pathlib import Path
# __init__.py
import pymysql
pymysql.install_as_MySQLdb()
# 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/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-x!)cojyro)mcft%4r^8&wsn9f8o!5px1=@6mx4eu73ydczx&)j'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*', 'a.debin.cc']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ec_user',
'authentication',
'diagnose'
]
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 = 'educheck.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'educheck.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
# }
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 使用 MySQL 数据库
'NAME': 'educheck', # 数据库名称
'USER': 'root', # 数据库用户名
'PASSWORD': 'pacpac123.', # 数据库密码
'HOST': '127.0.0.1', # 数据库主机(如果数据库在本地就用 localhost
'PORT': '3306', # MySQL 默认端口是 3306
}
}
# Password validation
# https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
AUTH_USER_MODEL = 'ec_user.EcUser'
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer', # 只返回 JSON 格式的响应
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'authentication.authentication.CustomTokenAuthentication',
],
}
ERROR_CODE_MAP = {
# 1000 - 用户相关错误
# 2000 - 生成试卷相关错误
'2001': 'user not authorized to generate paper for this subject',
'2002': 'user has no remaining usage count for this subject',
'2003': 'user has no school info',
# 试卷查看
'2004': 'record file not found',
# 试卷下载
'2005': 'requested file not found'
}
OPAI_API_KEY = 'e119bd6c-a22a-404e-a002-6d72a2cea65d'
OPAI_BASE_URL = 'https://ark.cn-beijing.volces.com/api/v3'
OPAI_IMG_BASE_URL = 'https://ark.cn-beijing.volces.com/api/v3'
OPAI_IMG_API_KEY = 'd04d386a-7c67-4927-8251-171a236583a6'
WKHTMLTOPDF_PATH = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'
# settings.py
# conda activate educheck
# python manage.py runserver 127.0.0.1:8000
# celery -A educheck worker -l info -P eventlet
# celery -A educheck beat -l info
CELERY_BROKER_URL = 'redis://127.0.0.1:6379/0' # 使用 Redis 作为消息中间件
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/0' # Redis 存储任务结果
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'