Docker-Compose Django Rest Framework Settings.py Scan

정규호·2024년 3월 30일
0

docker-compose -f ./docker-compose.app.local.yml exec designer_backend python manage.py list_settings

In Django, there isn't a built-in command in manage.py specifically designed to scan and display all settings from settings.py. However, you can create a custom management command to achieve this functionality.

Here's how you can create a custom management command to list and display all settings from settings.py:

Create a new directory named management inside your Django app directory if it doesn't exist already.
Inside the management directory, create another directory named commands.
Inside the commands directory, create a Python file (e.g., list_settings.py).
In list_settings.py, define a custom management command to list settings.
Execute the custom management command using python manage.py list_settings.
Here's an example implementation of list_settings.py:

Copy code
from django.conf import settings
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = 'List all settings from settings.py'

    def handle(self, *args, **options):
        self.stdout.write("Django settings:")
        for setting in dir(settings):
            if setting.isupper():
                self.stdout.write(f"{setting}: {getattr(settings, setting)}")

To use this custom command:

Save the list_settings.py file in yourapp/management/commands/.
Run the command python manage.py list_settings.
This command will iterate through all settings in settings.py and print their names and values. Make sure to replace yourapp with the name of your Django app.

profile
The Man Who Lift

0개의 댓글

관련 채용 정보