diff --git a/django_code/django_code/hosts.py b/django_code/django_code/hosts.py new file mode 100644 index 0000000..aa923ed --- /dev/null +++ b/django_code/django_code/hosts.py @@ -0,0 +1,7 @@ +from django.conf import settings +from django_hosts import patterns, host + +host_patterns = patterns('', + host(r"django-testing", settings.ROOT_URLCONF, name="django-testing"), + host(r"redirect", 'website_redirection.urls', name="redirect"), +) diff --git a/django_code/django_code/settings.py b/django_code/django_code/settings.py index 1f3e16a..c45e312 100644 --- a/django_code/django_code/settings.py +++ b/django_code/django_code/settings.py @@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/4.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.2/ref/settings/ """ - +import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -23,10 +23,9 @@ BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = 'django-insecure-71%)_#e#o9-dl2o^6mfud-*rw+4+8vy-nd*bzeier&(34ap-p9' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = ['reverse.tryton.geeraert.eu','192.168.4.100','django.tryton.geeraert.eu','localhost'] +DEBUG = os.getenv("DEBUG") +ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS").split(",") # Application definition @@ -38,9 +37,11 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'bootstrap5', + 'django_hosts', ] MIDDLEWARE = [ + 'django_hosts.middleware.HostsRequestMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -48,9 +49,13 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django_hosts.middleware.HostsResponseMiddleware', ] ROOT_URLCONF = 'django_code.urls' +ROOT_HOSTCONF = 'django_code.hosts' +DEFAULT_HOST = 'django-testing' + TEMPLATES = [ { diff --git a/django_code/django_code/urls.py b/django_code/django_code/urls.py index 2bdd87f..8b00ee6 100644 --- a/django_code/django_code/urls.py +++ b/django_code/django_code/urls.py @@ -27,6 +27,7 @@ from stash_management import apps as stashapp from stash_management import views as stashview from website_redirection import apps as website_redirectionapp + urlpatterns = [ # path('admin/', admin.site.urls), diff --git a/django_code/website_redirection/templates/redirect_form.html b/django_code/website_redirection/templates/redirect_form.html index d621809..364665a 100644 --- a/django_code/website_redirection/templates/redirect_form.html +++ b/django_code/website_redirection/templates/redirect_form.html @@ -259,7 +259,7 @@
Download form
-