django rest_framework 完整项目的配置项(seeting.py)

"""
Django settings for ProjectPrictice project.

Generated by 'django-admin startproject' using Django 3.0.1.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4roz-k6)(!$ql11ocuv%*grfo8)ogz5dm1eg43s(#m)wr94#5-'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders', #跨域
    'chouti', #应用
    'chouti.templatetags', #模板
    'newapp', #应用
    'newappagin',#应用
    'rest_framework', #框架
    'debug_toolbar', #工具
    'django_filters' #过滤器
    # 'blog.apps.BlogpConfig',

]
MIDDLEWARE = [
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    '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 = 'ProjectPrictice.urls'
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
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',
                'django.template.context_processors.media',
                'chouti.tools.context_processors.index',

            ],
            'libraries': {
                "my_tag": "chouti.templatetags.my_tag",
            },
        },
    },
]

WSGI_APPLICATION = 'ProjectPrictice.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
#
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

#     'default':{
#         'ENGINE': 'django.db.backends.mysql',
#         'NAME': 'crmdata',  # 你的数据库名称
#         'USER': 'root',  # 你的数据库用户名
#         'PASSWORD': '123456',  # 你的数据库密码
#         'HOST': '127.0.0.1',  # 你的数据库主机,留空默认为localhost
#         'PORT': '3306',  # 你的数据库端口
    }

}

# Password validation
# https://docs.djangoproject.com/en/3.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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True
REST_FRAMEWORK = {
#     配置响应数据格式
#     'DEFAULT_RENDERER_CLASSES':[
#     'rest_framework.renderers.JSONRenderer',
#     'rest_framework.renderers.BrowsableAPIRenderer',
#     ],

#     限流配置
#      'DEFAULT_THROTTLE_CLASSES': (
#         'rest_framework.throttling.AnonRateThrottle',  # 匿名用户,未登录的
#         'rest_framework.throttling.UserRateThrottle'  # 经过登录之后的用户
#     ),
#     'DEFAULT_THROTTLE_RATES': {
#         'anon': '2/minute',
#         'user': '5/minute',
#     },

    #  # 自定义认证类路径
    "DEFAULT_AUTHENTICATION_CLASSES": [
    #
    # "rest_framework.authentication.BasicAuthentication,",
    # "rest_framework.authentication.SessionAuthentication",
                                       ],
    #配置过滤
"DEFAULT_FILTER_BACKENDS": [
    'django_filters.rest_framework.DjangoFilterBackend'
],
     # 权限定义
    "DEFAULT_PERMISSION_CLASSES": [
      # 'rest_framework.permissions.AllowAny',
    ],

     #全局使用分页
    # "rest_framework.pagination.PageNumberPagination",
    # "PAGE_SIZE":100
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',


#     # 自定义权限类路径,这里是使用的默认的,自定义的可以把路径写在这里
#     "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
    #定义捕获异常 (自定义)
    'EXCEPTION_HANDLER':'chouti.exception.exception_handeler_heleper',

    #定义捕获异常 (未定义)
    # 'EXCEPTION_HANDLER':'rest_framework.views.exception_handeler_heleper',
    #版本控制器
    'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.URLPathVersioning',
    'DEFAULT_VERSION': 'v1',  # 默认的版本
    'ALLOWED_VERSIONS': ['v1', 'v2'],  # 有效的版本
    'VERSION_PARAM': 'version',  # 版本的参数名与URL conf中一致

}


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS=(
    os.path.join(BASE_DIR, 'static'),
)
APPEND_SLASH = False
MEDIA_URL = '/file/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'file')
CACHES={
    'default':{
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': os.path.join(BASE_DIR,'cache'),
        }
}

DEBUG = True
INTERNAL_IPS = [
    # ...
    '127.0.0.1',
    # ...
]

LOGGING = {

    'version': 1,

    'disable_existing_loggers': False,

    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',

        },

    },

    'loggers': {

        'django.db.backends': {

            'handlers': ['console'],

            'level': 'DEBUG' if DEBUG else 'INFO',

        },

    },

}

ps:请注意看添加备注的地方

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小赖同学啊

跟着大师走,路不会太差

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值