added 404 page + prepared for production setup
This commit is contained in:
parent
4f5f12473d
commit
72ad6ec081
3
.env.template
Normal file
3
.env.template
Normal file
@ -0,0 +1,3 @@
|
||||
DJANGO_SECRET_KEY=
|
||||
DJANGO_ENV=prod
|
||||
DJANGO_HOSTS=localhost,127.0.0.1
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
__pycache__
|
||||
db.sqlite3
|
||||
/db.sqlite3
|
||||
/.env
|
||||
|
@ -9,25 +9,28 @@ https://docs.djangoproject.com/en/5.1/topics/settings/
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.1/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
APP_VERSION = "0.0.1"
|
||||
APP_VERSION = "0.1.0"
|
||||
|
||||
load_dotenv(BASE_DIR / ".env")
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-^*x5i_#=$9kuj6k^v0cy5dqefmzo%j*i&0w93i%!zmgsa_z)2z'
|
||||
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = os.environ.get("DJANGO_ENV", "dev").lower() != "prod"
|
||||
|
||||
ALLOWED_HOSTS = ["localhost", "192.168.2.68"]
|
||||
ALLOWED_HOSTS = list(map(lambda h: h.strip(), os.environ.get("DJANGO_HOSTS", "localhost,127.0.0.1").split(",")))
|
||||
|
||||
|
||||
# Application definition
|
||||
@ -57,8 +60,7 @@ ROOT_URLCONF = 'TimeDispatcher.urls'
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates']
|
||||
,
|
||||
'DIRS': [BASE_DIR / 'templates'],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
@ -111,7 +113,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = 'Europe/Zurich'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
@ -121,7 +123,12 @@ USE_TZ = True
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
||||
|
||||
|
||||
STATICFILES_DIRS = [
|
||||
BASE_DIR / "dispatcher" / "static"
|
||||
]
|
||||
STATIC_URL = 'static/'
|
||||
_STATIC_ROOT = BASE_DIR / "dispatcher" / "static"
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
||||
|
@ -14,9 +14,10 @@ Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, register_converter
|
||||
from django.urls import path, register_converter, re_path
|
||||
from django.views.static import serve
|
||||
|
||||
from TimeDispatcher import settings
|
||||
from TimeDispatcher.converters import DateConverter, YearMonthConverter
|
||||
from dispatcher import views
|
||||
|
||||
@ -41,3 +42,6 @@ urlpatterns = [
|
||||
path("clockings/<date:date>/", views.set_clocking, name="set_clocking"),
|
||||
path("sagex/<int:id>/<year_month:month>/", views.set_real_sagex, name="set_real_sagex"),
|
||||
]
|
||||
|
||||
if not settings.DEBUG:
|
||||
urlpatterns.append(re_path(r"^static/(?P<path>.*)$", serve, {"document_root": settings._STATIC_ROOT}))
|
@ -1,8 +1,9 @@
|
||||
from TimeDispatcher.settings import APP_VERSION
|
||||
from TimeDispatcher.settings import APP_VERSION, DEBUG
|
||||
|
||||
|
||||
def version(request):
|
||||
return {
|
||||
"debug": DEBUG,
|
||||
"version": APP_VERSION
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,12 @@ footer .sep {
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
footer .debug {
|
||||
margin-right: auto;
|
||||
font-style: italic;
|
||||
color: #ffb33d;
|
||||
}
|
||||
|
||||
main {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
|
20
dispatcher/static/error.css
Normal file
20
dispatcher/static/error.css
Normal file
@ -0,0 +1,20 @@
|
||||
.wrapper {
|
||||
margin: auto;
|
||||
max-width: 25em;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2em;
|
||||
}
|
||||
|
||||
.desc {
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.url {
|
||||
font-family: monospace;
|
||||
background-color: rgba(255, 255, 255, 0.11);
|
||||
padding: 0.1em 0.4em;
|
||||
border-radius: 4px;
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
Django~=5.1.5
|
||||
djangorestframework~=3.15.2
|
||||
djangorestframework~=3.15.2
|
||||
python-dotenv~=1.0.1
|
13
templates/404.html
Normal file
13
templates/404.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% block title %}404 Not Found{% endblock %}
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="{% static "error.css" %}">
|
||||
{% endblock %}
|
||||
{% block footer %}{% endblock %}
|
||||
{% block main %}
|
||||
<div class="wrapper">
|
||||
<h1 class="title">Page not found</h1>
|
||||
<p class="desc">Oops, page <span class="url">{{ request.path }}</span> could not be found. Go back to <a href="{% url "dashboard" %}">Dashboard</a></p>
|
||||
</div>
|
||||
{% endblock %}
|
@ -22,6 +22,7 @@
|
||||
{% block main %}{% endblock %}
|
||||
</main>
|
||||
<footer>
|
||||
{% if debug %}<span class="debug">Debug</span>{% endif %}
|
||||
<span><i>Time Dispatcher v{{ version }}</i></span>
|
||||
<span class="sep"></span>
|
||||
<span><a href="https://git.kb28.ch/HEL/TimeDispatcher" target="_blank">Gitea</a></span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user