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

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.dockerignore
.gitignore
.venv
docker-compose.yml
Dockerfile
volumes

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
.idea/
.venv/
**/__pycache__/
volumes/

7
Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM python:3.10
ENV PYTHONUNBUFFERED=1
WORKDIR /code/
COPY requirements.txt .
RUN pip install --no-cache-dir --requirement requirements.txt
COPY . .
ENTRYPOINT ["./entrypoint.sh"]

9
docker-compose.yml Normal file
View File

@@ -0,0 +1,9 @@
services:
web:
build:
context: .
ports:
- "80:8000"
volumes:
- .:/code:r

12
entrypoint.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
if [ "$DJANGO_PRODUCTION_MODE" == "true" ]; then
echo "starting production server ..."
gunicorn --bind=0.0.0.0:8000 --workers=2 gaehsnitzproject.wsgi
else
echo "starting development server ..."
python manage.py runserver 0.0.0.0:8000
fi

0
gaehsnitz/__init__.py Normal file
View File

6
gaehsnitz/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class GaehsnitzConfig(AppConfig):
name = "gaehsnitz"
verbose_name = "Gähsnitz Open Air"

View File

@@ -0,0 +1,79 @@
html, body, div,
h1, h2, h3, h4, h5, h6,
a, p, b, i,
form, label, input,
table, thead, tbody, tr, td {
margin: 0;
border: none;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
font-size: 14px;
}
@media only screen and (min-width: 600px) and (max-width: 899px) {
html, body {
font-size: 16px;
}
}
@media only screen and (min-width: 900px) {
html, body {
font-size: 18px;
}
}
body {
display: flex;
flex-direction: column;
align-items: center;
background-color: #111111;
color: #EEEEEE;
}
#title, #navi, #content {
flex: 0 1 auto;
width: 95%;
max-width: 1200px;
margin: 8px;
}
#title {
margin-top: 16px;
font-size: 1.6rem;
text-align: center;
color: #EE9933;
text-shadow: 0 0 16px #EE9933;
}
#navi {
border-top: 1px solid #663322;
border-bottom: 1px solid #663322;
color: #663322;
padding: 8px 0;
text-align: center;
}
a {
text-decoration: none;
color: #EE9933;
transition: color 100ms;
}
a:hover, a:focus {
color: #EEEEEE;
}
h1 {
margin: 0 0 12px;
font-size: 1.3rem;
font-weight: bold;
color: #EECC66;
}
p {
margin: 6px 0 10px;
}

View File

@@ -0,0 +1,30 @@
{% load static %}
<!DOCTYPE html>
<html lang="de">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<title>Gähsnitz Open Air</title>
<link rel="stylesheet" type="text/css" href="{% static 'gaehsnitz/style.css' %}">
</head>
<body>
<div id="title">
Gähsnitz Open Air 2022
</div>
<div id="navi">
<a href="#">News</a>
|
<a href="#">A-Z</a>
|
<a href="#">Bands</a>
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>

View File

@@ -0,0 +1,9 @@
{% extends "gaehsnitz/base.html" %}
{% block content %}
<h1>Bald, dooo!</h1>
<p>Das bisschen Website macht sich von allein, nimmt man an.</p>
{% endblock %}

7
gaehsnitz/urls.py Normal file
View File

@@ -0,0 +1,7 @@
from django.urls import path
from gaehsnitz.views import IndexView
urlpatterns = [
path("", IndexView.as_view(), name="index"),
]

5
gaehsnitz/views.py Normal file
View File

@@ -0,0 +1,5 @@
from django.views.generic import TemplateView
class IndexView(TemplateView):
template_name = "gaehsnitz/index.html"

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

21
manage.py Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gaehsnitzproject.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
django==4.0.4
gunicorn==20.1.0