create basic django app serving the Gähsnitz website

This commit is contained in:
2022-05-20 22:32:32 +02:00
commit 3b38c9fdec
18 changed files with 286 additions and 0 deletions

View File

View File

@@ -0,0 +1,77 @@
import os
def _get_env_production_mode():
env_var = os.environ.get("DJANGO_PRODUCTION_MODE", "false")
return env_var.lower() == "true"
def _get_env_secret_key():
env_var = os.environ.get("DJANGO_SECRET_KEY")
assert env_var is not None, "DJANGO_SECRET_KEY environment variable must be set when using production mode"
return env_var
def _get_env_allowed_hosts():
env_var = os.environ.get("DJANGO_ALLOWED_HOSTS")
assert env_var is not None, "DJANGO_ALLOWED_HOSTS environment variable must be set when using production mode"
return [host.strip() for host in env_var.split(",")]
def _get_env_static_root():
env_var = os.environ.get("DJANGO_STATIC_ROOT")
assert env_var is not None, "DJANGO_STATIC_ROOT environment variable must be set when using production mode"
return env_var
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PRODUCTION = _get_env_production_mode()
if PRODUCTION:
SECRET_KEY = _get_env_secret_key()
DEBUG = False
ALLOWED_HOSTS = _get_env_allowed_hosts()
STATIC_ROOT = _get_env_static_root()
else:
SECRET_KEY = "LqKSgoFtED4IFYxf01lBi5MEI4ExSayCakwLjyuzytDJ7vuMq9"
DEBUG = True
ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [
"gaehsnitz",
"django.contrib.contenttypes",
"django.contrib.staticfiles",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "gaehsnitzproject.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
],
},
},
]
WSGI_APPLICATION = "gaehsnitzproject.wsgi.application"
TIME_ZONE = "Europe/Berlin"
USE_I18N = False
USE_L10N = False
USE_TZ = True
STATIC_URL = "/static/"

5
gaehsnitzproject/urls.py Normal file
View File

@@ -0,0 +1,5 @@
from django.urls import path, include
urlpatterns = [
path("", include(("gaehsnitz.urls", "gaehsnitz"))),
]

7
gaehsnitzproject/wsgi.py Normal file
View File

@@ -0,0 +1,7 @@
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gaehsnitzproject.settings')
application = get_wsgi_application()