This is the Django settings file for the movie project.
It sets up various configurations such as database, middleware, static and media files location, etc.
import os import pymysql pymysql.install_as_MySQLdb() # Installs MySQLdb module as default database engine
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file))) # Base directory of the project SECRET_KEY = “r^n(t&=!%nn!+5*^qsto_7o0b41x-*uo1u01)^px-71xbj!u4s” # Secret key for security purposes DEBUG = True # Whether to run in debug mode or not ENV_PROFILE = os.getenv(“ENV”) # Environment profile variable (if set)
Allowed hosts (only used in production environment)
if DEBUG: ALLOWED_HOSTS=[‘*’,] else: ALLOWED_HOSTS = [‘0.0.0.0’,‘localhost’]
INSTALLED_APPS = [
"simpleui", # SimpleUI admin theme
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework", # Django REST framework for building API endpoints
'corsheaders', # CORS headers middleware for handling cross-origin requests
"user", # User app for handling user authentication and authorization
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware', # CORS 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 = “movie.urls” # Project’s root URL configuration file
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [], # Custom template directories
"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",
"user.context_processors.env_profile", # Environment profile context processor for templates
'django.template.context_processors.media',
]
},
}
]
SIMPLEUI_HOME_INFO = False # Disable SimpleUI home information
WSGI_APPLICATION = “movie.wsgi.application” # WSGI application entry point
Database configuration (using SQLite in development)
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
Cache configuration (using file-based cache backend)
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': os.path.join(BASE_DIR, 'tmp/django_cache'),
}
}
Password validation settings
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"},
]
LANGUAGE_CODE = “zh-hans” # Default language code TIME_ZONE = “Asia/Shanghai” # Default time zone USE_I18N = True USE_L10N = True USE_TZ = True
STATIC_ROOT=os.path.join(BASE_DIR, ‘staticfiles/’) # Static files root directory (for serving static files in production) STATICFILES_DIRS = (os.path.join(BASE_DIR, “static”),) # Custom static files directories STATIC_URL = “/static/” # URL prefix for static files MEDIA_ROOT = os.path.join(BASE_DIR, “media”) # Media files root directory MEDIA_URL = “/media/” # URL prefix for media files
DEFAULT_AUTO_FIELD=‘django.db.models.BigAutoField’ # Default auto field type




