diff --git a/README.md b/README.md index 1cbb400b..5e95ceef 100644 --- a/README.md +++ b/README.md @@ -341,6 +341,7 @@ If libvirt warns `Host SMBIOS information is not available`, install `dmidecode` | `CSRF_TRUSTED_ORIGINS` | extra trusted origins, e.g. `https://wvc.example.com` | | `WEBVIRTCLOUD_HTTPS=1` | HTTPS profile, see [HTTPS and reverse proxy](#https-and-reverse-proxy) | | `WEBVIRTCLOUD_SERIAL_CONSOLE=1` | serial console, see [Serial console](#serial-console) | +| `WEBVIRTCLOUD_DEBUG=1` | Django debug mode: error pages show the traceback and settings; for trying things out only, never on a panel others use | | `WEBVIRTCLOUD_DB_HOST` | use PostgreSQL instead of sqlite (new installs); `WEBVIRTCLOUD_DB_PORT`/`_NAME`/`_USER`/`_PASSWORD` default to 5432/webvirtcloud/webvirtcloud/empty | | `EMAIL_HOST`, `EMAIL_PORT`, `EMAIL_HOST_USER`, `EMAIL_HOST_PASSWORD`, `EMAIL_USE_TLS` | SMTP for e-mail OTP | | `WEBVIRTCLOUD_LOG_FILE` | log file (default `data/webvirtcloud.log`, rotated at 10 MB × 5) | diff --git a/webvirtcloud/settings.py.template b/webvirtcloud/settings.py.template index e9547af3..a4b0e8ea 100644 --- a/webvirtcloud/settings.py.template +++ b/webvirtcloud/settings.py.template @@ -26,7 +26,8 @@ if not SECRET_KEY: except OSError: pass -DEBUG = False +# WEBVIRTCLOUD_DEBUG=1 shows error details on the pages: for trying things out only +DEBUG = os.getenv("WEBVIRTCLOUD_DEBUG") == "1" MAC_OUI = '52:54:10' diff --git a/webvirtcloud/tests/test_settings_env.py b/webvirtcloud/tests/test_settings_env.py index 76a74409..f27d9afd 100644 --- a/webvirtcloud/tests/test_settings_env.py +++ b/webvirtcloud/tests/test_settings_env.py @@ -12,7 +12,7 @@ from django.test import SimpleTestCase, TestCase, override_settings # Env vars that change the settings; removed from the inherited environment so # every case starts from the defaults. CONFIG_VARS = [ - "WEBVIRTCLOUD_HTTPS", "ALLOWED_HOSTS", + "WEBVIRTCLOUD_HTTPS", "WEBVIRTCLOUD_DEBUG", "ALLOWED_HOSTS", "EMAIL_HOST", "EMAIL_PORT", "EMAIL_HOST_USER", "EMAIL_HOST_PASSWORD", "EMAIL_USE_TLS", "WEBVIRTCLOUD_DB_HOST", "WEBVIRTCLOUD_DB_PORT", "WEBVIRTCLOUD_DB_NAME", "WEBVIRTCLOUD_DB_USER", "WEBVIRTCLOUD_DB_PASSWORD", @@ -132,3 +132,13 @@ class DatabaseEnvTestCase(SimpleTestCase): {"ENGINE": "django.db.backends.postgresql", "PORT": "5432", "NAME": "webvirtcloud", "USER": "webvirtcloud", "PASSWORD": ""}, ) + + +class DebugEnvTestCase(SimpleTestCase): + def test_debug_is_off_unless_asked(self): + self.assertFalse(load_settings({}, ["DEBUG"])["DEBUG"]) + self.assertFalse(load_settings({"WEBVIRTCLOUD_DEBUG": "0"}, ["DEBUG"])["DEBUG"]) + self.assertTrue(load_settings({"WEBVIRTCLOUD_DEBUG": "1"}, ["DEBUG"])["DEBUG"]) + + def test_debug_loads_the_urls(self): + run_manage({"WEBVIRTCLOUD_DEBUG": "1"}, "check") diff --git a/webvirtcloud/urls.py b/webvirtcloud/urls.py index 30d32004..a111d2d2 100644 --- a/webvirtcloud/urls.py +++ b/webvirtcloud/urls.py @@ -43,13 +43,9 @@ urlpatterns = [ re_path(r"^api/(?:.*/)?$", api_not_found), ] -if settings.DEBUG: - try: - import debug_toolbar +# settings-dev installs the toolbar; WEBVIRTCLOUD_DEBUG alone does not +if "debug_toolbar" in settings.INSTALLED_APPS: + import debug_toolbar - urlpatterns += [ - path("__debug__/", include(debug_toolbar.urls)), - ] - except ImportError: - pass + urlpatterns += [path("__debug__/", include(debug_toolbar.urls))]