美文网首页
新建项目setting配置

新建项目setting配置

作者: Yanl__ | 来源:发表于2023-04-26 16:23 被阅读0次

数据库配置

DATABASES = {
      'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '-',
        'USER': '-',
        'PASSWORD': '-',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}

时间 admin中文 static、auth模块拓展、rest_framework 配置


# 改成中文
LANGUAGE_CODE = 'zh-hans'
# TIME_ZONE = 'UTC'
# 修改为北京时间
# 同时设置time_zone 和 use_tz  设置的上海时区才会生效
TIME_ZONE = 'Asia/Shanghai'
USE_TZ = False
DEBUG = True
STATIC_URL = '/static/'
# 增加static_root
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'staticfiles'),
    os.path.join(BASE_DIR, 'static'),
    # 设置app的静态资源文件夹
    # os.path.join(BASE_DIR, 'index/Mystatic'),
]
# 配置auth的拓展
AUTH_USER_MODEL = 'login.MyUser'

#INSTALLED_APPS中需要增加两个app
#    'rest_framework',  # restful api
#    'rest_framework.authtoken',  # drf自带的Token认证 会生成一张token表
# restframework全局配置
REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 50,
    'DATATIME_FORMAT': '%Y-%m-%d %H:%M:%S',
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ],
    'DEFAULT_PARSER_CLASSES': [  # 解析request.data
        'rest_framework.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser'
    ],
    'DEFAULT_AUTHENTICATION_CLASSES': [
        # 'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        # 'rest_framework.authentication.TokenAuthentication'  # 需要在installed_app 中加上authtoken
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.AllowAny',
        # 'rest_framework.permissions.IsAuthenticated',  # 全局要求登录
    ]
}

相关文章

网友评论

      本文标题:新建项目setting配置

      本文链接:https://www.haomeiwen.com/subject/qfvvjdtx.html