mirror of
https://github.com/lemeow125/DRF_Template.git
synced 2025-09-18 05:29:37 +08:00
Move to uv/pyproject and overhaul project structure
This commit is contained in:
commit
fbb76f8196
26 changed files with 1981 additions and 0 deletions
241
src/core/settings.py
Normal file
241
src/core/settings.py
Normal file
|
@ -0,0 +1,241 @@
|
|||
"""
|
||||
Django settings for the project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 5.2.5.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.2/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from core.config import Config
|
||||
|
||||
# Config initialization
|
||||
config = Config().get_config()
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = config.SECRET_KEY
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = config.DEBUG
|
||||
|
||||
CORS_ALLOWED_ORIGINS = config.CORS_ORIGINS
|
||||
ALLOWED_HOSTS = config.ALLOWED_HOSTS
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"core",
|
||||
"unfold",
|
||||
"unfold.contrib.filters",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django_extensions",
|
||||
"rest_framework",
|
||||
"rest_framework_simplejwt",
|
||||
"corsheaders",
|
||||
"djoser",
|
||||
"drf_spectacular",
|
||||
*(["silk"] if config.DEBUG else []),
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
# Silk enabled on DEBUG
|
||||
*(["silk.middleware.SilkyMiddleware"] if config.DEBUG else []),
|
||||
"whitenoise.middleware.WhiteNoiseMiddleware",
|
||||
"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",
|
||||
]
|
||||
|
||||
DJANGO_LOG_LEVEL = config.DJANGO_LOG_LEVEL
|
||||
DEBUG_PROPAGATE_EXCEPTIONS = [True if config.DEBUG else False]
|
||||
|
||||
ROOT_URLCONF = "core.urls"
|
||||
|
||||
# Email Templates
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [
|
||||
BASE_DIR / "core/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 = "core.wsgi.application"
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "db.sqlite3",
|
||||
}
|
||||
}
|
||||
|
||||
# Storage
|
||||
|
||||
STORAGES = {
|
||||
"staticfiles": {
|
||||
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/5.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/5.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = config.TIMEZONE
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = config.USE_TZ
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
||||
|
||||
STATIC_URL = "static/"
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
# REST Framework
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
"DEFAULT_AUTHENTICATION_CLASSES": (
|
||||
"rest_framework_simplejwt.authentication.JWTAuthentication",
|
||||
),
|
||||
"DEFAULT_THROTTLE_CLASSES": [
|
||||
"rest_framework.throttling.AnonRateThrottle",
|
||||
"rest_framework.throttling.UserRateThrottle",
|
||||
],
|
||||
"DEFAULT_THROTTLE_RATES": {"anon": "60/min", "user": "240/min"},
|
||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||
}
|
||||
|
||||
|
||||
# Authentication
|
||||
DJOSER = {
|
||||
"SEND_ACTIVATION_EMAIL": True,
|
||||
"SEND_CONFIRMATION_EMAIL": True,
|
||||
"PASSWORD_RESET_CONFIRM_URL": "reset_password/confirm/{uid}/{token}",
|
||||
"ACTIVATION_URL": "activation/{uid}/{token}",
|
||||
"USER_AUTHENTICATION_RULES": ["djoser.authentication.TokenAuthenticationRule"],
|
||||
"SERIALIZERS": {
|
||||
"user": "accounts.serializers.CustomUserSerializer",
|
||||
"current_user": "accounts.serializers.CustomUserSerializer",
|
||||
"user_create": "accounts.serializers.CustomUserRegistrationSerializer",
|
||||
},
|
||||
"PERMISSIONS": {
|
||||
# Unused endpoints set to admin only
|
||||
"username_reset": ["rest_framework.permissions.IsAdminUser"],
|
||||
"username_reset_confirm": ["rest_framework.permissions.IsAdminUser"],
|
||||
"set_username": ["rest_framework.permissions.IsAdminUser"],
|
||||
"set_password": ["rest_framework.permissions.IsAdminUser"],
|
||||
},
|
||||
}
|
||||
|
||||
SIMPLE_JWT = {
|
||||
"ACCESS_TOKEN_LIFETIME": config.ACCESS_TOKEN_LIFETIME_MINUTES,
|
||||
"REFRESH_TOKEN_LIFETIME": config.REFRESH_TOKEN_LIFETIME_DAYS,
|
||||
"ROTATE_REFRESH_TOKENS": True,
|
||||
"BLACKLIST_AFTER_ROTATION": True,
|
||||
}
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||
"OPTIONS": {
|
||||
"min_length": 8,
|
||||
},
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||
},
|
||||
# core/validators.py
|
||||
{
|
||||
"NAME": "core.validators.SpecialCharacterValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "core.validators.LowercaseValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "core.validators.UppercaseValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "core.validators.NumberValidator",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Swagger / OpenAPI
|
||||
SPECTACULAR_SETTINGS = {
|
||||
"VERSION": "1.0.0",
|
||||
"SERVE_INCLUDE_SCHEMA": False,
|
||||
}
|
||||
|
||||
# Pygraphviz
|
||||
GRAPH_MODELS = {
|
||||
"all_applications": True,
|
||||
"group_models": True,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue