
Custom Django Commands
Management commands, BaseCommand, argument parsing, scheduling, cron jobs, automation
1Where should a custom Django management command file be placed to be automatically detected?
Where should a custom Django management command file be placed to be automatically detected?
Respuesta
Custom Django management commands must be placed in the management/commands/ directory of a Django application. This directory must contain an __init__.py file in both management/ and commands/. Django automatically scans this path to discover available commands. The Python filename becomes the command name executable via manage.py.
2Which base class should be used to create a custom Django management command?
Which base class should be used to create a custom Django management command?
Respuesta
BaseCommand is the standard base class provided by django.core.management.base for creating custom commands. It provides the necessary infrastructure: argument parsing, output color handling, error management, and integration with manage.py. The handle() method must be implemented to contain the command logic.
3How to define positional arguments in a custom Django management command?
How to define positional arguments in a custom Django management command?
Respuesta
The add_arguments() method allows defining command arguments using the argparse parser. For positional arguments, use parser.add_argument('name') without a dash prefix. You can specify nargs for the number of expected arguments ('+' for one or more, '*' for zero or more). Arguments are then accessible via the options dictionary in handle().
Which method should be used to display a success message with appropriate colors in a Django command?
How to signal an error that stops Django command execution with a non-zero exit code?
+15 preguntas de entrevista
Otros temas de entrevista Django
Python Basics
Python OOP
Django Fundamentals
Django Models - Basics
Django Views
Django Templates
Django Forms
Advanced QuerySets
Django Authentication
Django Middleware
Django Admin
Django REST Framework
Django Signals
File Upload
Django Caching
Django Sessions
Django Email
Django Testing
Django Security
Django Deployment
Advanced Django ORM
Django Performance
Django & Celery
Django Channels
Django & GraphQL
Django & Docker
Django in Microservices Ecosystem
Django Internationalization
Django Design Patterns
Django Async & ASGI
Settings & Production Configuration
Observability & Monitoring
Domina Django para tu próxima entrevista
Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.
Empieza gratis