src/hdalab/views/__init__.py
author ymh <ymh.work@gmail.com>
Fri, 19 Jul 2024 09:38:03 +0200
changeset 704 b5835dca2624
parent 546 0ca66b267d15
child 693 09e00f38d177
permissions -rw-r--r--
Adapt renkan preview to uses chrome headless/puppeteer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
546
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     1
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     2
import logging
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     3
import sys
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     4
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     5
from django.conf import settings
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     6
from django.shortcuts import render
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     7
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     8
logger = logging.getLogger(__name__)
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     9
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    10
def server_error(request):
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    11
    response = None
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    12
    try:
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    13
        response = render(request, '500.html', {'base_url': settings.BASE_URL})
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    14
    except:
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    15
        import traceback
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    16
        logger.error("server_error %s : %s", sys.exc_info()[0], traceback.format_exc())
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    17
    response.status_code = 500
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    18
    return response