From 425b5101c1b1f12f0f1ebddbb217c146ec82c840 Mon Sep 17 00:00:00 2001 From: Svetlitski Date: Wed, 12 Feb 2020 21:18:35 -0800 Subject: [PATCH] Do not show Django's builtin admin login page outside of development --- csm_web/csm_web/admin.py | 7 +++++++ csm_web/csm_web/apps.py | 5 +++++ csm_web/csm_web/settings.py | 4 ++-- csm_web/csm_web/templates/csm_web/admin_login.html | 6 ++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 csm_web/csm_web/admin.py create mode 100644 csm_web/csm_web/apps.py create mode 100644 csm_web/csm_web/templates/csm_web/admin_login.html diff --git a/csm_web/csm_web/admin.py b/csm_web/csm_web/admin.py new file mode 100644 index 00000000..45de506a --- /dev/null +++ b/csm_web/csm_web/admin.py @@ -0,0 +1,7 @@ +from django.contrib.admin import AdminSite as DefaultAdminSite +from django.conf import settings + + +class AdminSite(DefaultAdminSite): + if settings.DJANGO_ENV != settings.DEVELOPMENT: + login_template = 'admin_login.html' diff --git a/csm_web/csm_web/apps.py b/csm_web/csm_web/apps.py new file mode 100644 index 00000000..5c7b2b08 --- /dev/null +++ b/csm_web/csm_web/apps.py @@ -0,0 +1,5 @@ +from django.contrib.admin.apps import AdminConfig as DefaultAdminConfig + + +class AdminConfig(DefaultAdminConfig): + default_site = 'csm_web.admin.AdminSite' diff --git a/csm_web/csm_web/settings.py b/csm_web/csm_web/settings.py index 47de0d3b..708dd9ca 100644 --- a/csm_web/csm_web/settings.py +++ b/csm_web/csm_web/settings.py @@ -51,12 +51,12 @@ # Application definition INSTALLED_APPS = [ - "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "csm_web.apps.AdminConfig", "scheduler.apps.SchedulerConfig", "rest_framework", "social_django", @@ -83,7 +83,7 @@ TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], + "DIRS": ["./csm_web/csm_web/templates/csm_web/"], "APP_DIRS": True, "OPTIONS": { "context_processors": [ diff --git a/csm_web/csm_web/templates/csm_web/admin_login.html b/csm_web/csm_web/templates/csm_web/admin_login.html new file mode 100644 index 00000000..74b8b2f9 --- /dev/null +++ b/csm_web/csm_web/templates/csm_web/admin_login.html @@ -0,0 +1,6 @@ + + + + + +