django-management-command

Django management command without working db connection

只愿长相守 提交于 2019-12-20 03:54:28
问题 I have a number of projects that use the following configuration model: settings.py includes default configuration and config specifications, mainly used for development purposes. The default settings (including db settings) can be overridden by external configuration files, usually defined by admins for the various environments they manage. In order to ease the admins, I have written a management command and packaged separately, which adds the option to create example configuration files

Spurious newlines added in Django management commands

痞子三分冷 提交于 2019-12-10 12:41:36
问题 Running Django v1.10 on Python 3.5.0: from django.core.management.base import BaseCommand class Command(BaseCommand): def handle(self, *args, **options): print('hello ', end='', file=self.stdout) print('world', file=self.stdout) Expected output: hello world Actual output: hello world How do I correctly pass the ending character? I currently use a workaround of setting explicitly: self.stdout.ending = '' But this hack means you don't get all the features of the print function, you must use