123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- """
- Django settings for invoice_ocr project.
- Generated by 'django-admin startproject' using Django 3.1.4.
- For more information on this file, see
- https://docs.djangoproject.com/en/3.1/topics/settings/
- For the full list of settings and their values, see
- https://docs.djangoproject.com/en/3.1/ref/settings/
- """
- import os
- import time
- 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/3.1/howto/deployment/checklist/
- # SECURITY WARNING: keep the secret key used in production secret!
- SECRET_KEY = 'l56929t$rpl&(75-g20nnoe*@q7gxp9c)i*1lh2fi=4+p-4(mj'
- # SECURITY WARNING: don't run with debug turned on in production!
- DEBUG = True
- ALLOWED_HOSTS = ['119.3.54.245', '127.0.0.1']
- # Application definition
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'corsheaders',
- 'ocr',
- ]
- MIDDLEWARE = [
- 'django.middleware.security.SecurityMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'corsheaders.middleware.CorsMiddleware', # 跨域资源
- 'django.middleware.common.CommonMiddleware',
- # 'django.middleware.csrf.CsrfViewMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
- 'django.middleware.clickjacking.XFrameOptionsMiddleware',
- ]
- ROOT_URLCONF = 'invoice_ocr.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 = 'invoice_ocr.wsgi.application'
- # Database
- # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': BASE_DIR / 'db.sqlite3',
- }
- }
- # Password validation
- # https://docs.djangoproject.com/en/3.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',
- },
- ]
- # Internationalization
- # https://docs.djangoproject.com/en/3.1/topics/i18n/
- LANGUAGE_CODE = 'en-us'
- TIME_ZONE = 'UTC'
- USE_I18N = True
- USE_L10N = True
- USE_TZ = True
- # 日志:当运行出错时,记录在日志中,方便后续修改
- cur_path = os.path.dirname(os.path.realpath(__file__)) # log_path是存放日志的路径
- log_path = os.path.join(os.path.dirname(cur_path), 'logs')
- if not os.path.exists(log_path):os.mkdir(log_path) # 如果不存在这个logs文件夹,就自动创建一个
- LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': True,
- 'formatters': {
- # 日志格式
- 'standard': {
- 'format': '[%(asctime)s] [%(filename)s:%(lineno)d] [%(module)s:%(funcName)s] '
- '[%(levelname)s]- %(message)s'},
- 'simple': { # 简单格式
- 'format': '%(levelname)s %(message)s'
- },
- },
- # 过滤
- 'filters': {
- },
- # 定义具体处理日志的方式
- 'handlers': {
- # 默认记录所有日志
- 'default': {
- 'level': 'INFO',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(log_path, 'all-{}.log'.format(time.strftime('%Y-%m-%d'))),
- 'maxBytes': 1024 * 1024 * 5, # 文件大小
- 'backupCount': 5, # 备份数
- 'formatter': 'standard', # 输出格式
- 'encoding': 'utf-8', # 设置默认编码,否则打印出来汉字乱码
- },
- # 输出错误日志
- 'error': {
- 'level': 'ERROR',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(log_path, 'error-{}.log'.format(time.strftime('%Y-%m-%d'))),
- 'maxBytes': 1024 * 1024 * 5, # 文件大小
- 'backupCount': 5, # 备份数
- 'formatter': 'standard', # 输出格式
- 'encoding': 'utf-8', # 设置默认编码
- },
- # 控制台输出
- 'console': {
- 'level': 'DEBUG',
- 'class': 'logging.StreamHandler',
- 'formatter': 'standard'
- },
- # 输出info日志
- 'info': {
- 'level': 'INFO',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(log_path, 'info-{}.log'.format(time.strftime('%Y-%m-%d'))),
- 'maxBytes': 1024 * 1024 * 5,
- 'backupCount': 5,
- 'formatter': 'standard',
- 'encoding': 'utf-8', # 设置默认编码
- },
- },
- # 配置用哪几种 handlers 来处理日志
- 'loggers': {
- # 类型 为 django 处理所有类型的日志, 默认调用
- 'django': {
- 'handlers': ['default', 'console'],
- 'level': 'INFO',
- 'propagate': False
- },
- # log 调用时需要当作参数传入
- 'log': {
- 'handlers': ['error', 'info', 'console', 'default'],
- 'level': 'INFO',
- 'propagate': True
- },
- }
- }
- # 跨域增加忽略
- CORS_ALLOW_CREDENTIALS = True
- CORS_ORIGIN_ALLOW_ALL = True
- CORS_ORIGIN_WHITELIST = (
- 'http://*.*.*.*:*',
- )
- CORS_ALLOW_METHODS = (
- 'DELETE',
- 'GET',
- 'OPTIONS',
- 'PATCH',
- 'POST',
- 'PUT',
- 'VIEW',
- )
- CORS_ALLOW_HEADERS = (
- 'XMLHttpRequest',
- 'X_FILENAME',
- 'accept-encoding',
- 'authorization',
- 'content-type',
- 'dnt',
- 'origin',
- 'user-agent',
- 'x-csrftoken',
- 'x-requested-with',
- )
- STATIC_URL = '/static/'
|