1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

feat(settings): WEBVIRTCLOUD_DEBUG=1 turns on Django's debug mode

DEBUG was fixed to False in the template, and Docker builds settings.py
from it in each container: debug mode could only be had by editing the
file inside a running container. It is now read from the environment like
the other options; off unless the variable is 1.

The toolbar's URLs follow settings-dev, which installs the toolbar, not
DEBUG: with the dev packages present, DEBUG alone imported them without
the app and every URL lookup failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-09 09:05:38 +03:00
parent 47d2a34403
commit 23ce5de31e
4 changed files with 18 additions and 10 deletions

View file

@ -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) |

View file

@ -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'

View file

@ -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")

View file

@ -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))]