Django Settings Configuration
The settings.py file is a central configuration file in Django. It defines the setup of various components of the Django project, including database configuration, security parameters, installed apps, and more. Understanding this file is crucial for configuring and maintaining the SailPilot Django application.
Note
It’s essential to keep some settings like SECRET_KEY secure, especially in a production environment. Additionally, setting DEBUG to False in production is crucial for security.
Base Directory and Application Directory
BASE_DIR: This is the base directory of the Django project. It’s used to build paths to other directories and files in the project.APPS_DIR: Custom directory for Django applications. Adding this to the system path allows for easier importing of apps.
Security Settings
SECRET_KEY: A key used for cryptographic signing. Should be kept secret in production.DEBUG: Set to True in development for detailed error pages. Must be False in production.ALLOWED_HOSTS: A list of host/domain names that this Django site can serve.
Installed Apps
A list of Django and third-party apps used in the SailPilot project. This includes:
Django default apps like
django.contrib.admin,django.contrib.auth, etc.Django REST framework apps for API functionalities:
rest_framework,rest_framework.authtoken.Other apps like
corsheadersfor handling Cross-Origin Resource Sharing (CORS),django_qfor handling asynchronous tasks, and custom apps such aspoints,user.
Database Configuration
The DATABASES setting defines the database configuration. SailPilot uses a MySQL database with specific settings like autocommit and SQL mode.
DATABASES = {
'default': {
'NAME': 'hartisa1_sailpilot_app',
'ENGINE': 'mysql.connector.django',
'USER': 'hartisa1_sailpilot_app',
# ... other settings ...
}
}
REST Framework Settings
Configuration for Django REST framework, including default permission classes and authentication classes.
DEFAULT_PERMISSION_CLASSES: Sets the permission classes for API access.DEFAULT_AUTHENTICATION_CLASSES: Includes Token and JWT Authentication for secure API access.
Static and Media Files
Defines settings for static and media file management, including URLs and root paths for static and media files.
Internationalization and Time Zone
Settings related to language, time zone, and internationalization, ensuring SailPilot’s adaptability to different locales.
Email Configuration
Email settings for sending emails from the application, including SMTP configuration and default email addresses.
Note
Email credentials and settings should be secured and not exposed in a public repository.
Further Configurations
Additional settings include LOGIN_URL, custom JSON file paths, and more, tailoring the Django project to the specific needs of SailPilot.
See also
Django official documentation on settings: https://docs.djangoproject.com/en/4.0/ref/settings/