[Django]-Programmatically disable DEBUG in Django command

6๐Ÿ‘

โœ…

I think you have a couple of options here:

  1. Import settings and throw an error to remind yourself to turn debug off.

  2. Use the --settings= and set that equal to a file (e.g. gen_settings.py) file specifically for your generate_sitemaps command where DEBUG=False. Then create an alias for ./manage.py generate_sitemaps --settings=gen_settings

http://docs.djangoproject.com/en/dev/topics/settings/ warns specifically to not change the settings at runtime

Iโ€™ve used the second option before and it worked fairly well. Better than being annoyed after 2-3 hours =)

๐Ÿ‘คdting

1๐Ÿ‘

I am not really sure it helps you, but you can try:

from django.conf import settings

tmp = settings.DEBUG
settings.DEBUG = False
# some your actions
# ...
# ...
settings.DEBUG = tmp

Alternatively you can use separated settings file and set it in command line like

./manage.py your_command --settings=another_settings.py

And in that another_settings.py:

from .settings import *
DEBUG = False
๐Ÿ‘คMillioner

Leave a comment