src/hdalab/views/__init__.py
author ymh <ymh.work@gmail.com>
Thu, 12 Apr 2018 01:59:24 +0200
branchdocumentation
changeset 694 46da276fbb1b
parent 693 09e00f38d177
permissions -rw-r--r--
small doc corrections
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
693
09e00f38d177 Add hdabo/hdalab documentations
ymh <ymh.work@gmail.com>
parents: 546
diff changeset
     1
"""
09e00f38d177 Add hdabo/hdalab documentations
ymh <ymh.work@gmail.com>
parents: 546
diff changeset
     2
HDALab views.
546
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     3
693
09e00f38d177 Add hdabo/hdalab documentations
ymh <ymh.work@gmail.com>
parents: 546
diff changeset
     4
"""
546
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     5
import logging
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     6
import sys
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
from django.conf import settings
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
     9
from django.shortcuts import render
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    10
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    11
logger = logging.getLogger(__name__)
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    12
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    13
def server_error(request):
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    14
    response = None
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    15
    try:
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    16
        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
    17
    except:
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    18
        import traceback
0ca66b267d15 add custom 400, 500 and 404 pages
ymh <ymh.work@gmail.com>
parents: 266
diff changeset
    19
        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
    20
    response.status_code = 500
693
09e00f38d177 Add hdabo/hdalab documentations
ymh <ymh.work@gmail.com>
parents: 546
diff changeset
    21
    return response