mirror of https://github.com/snachodog/mybuddy.git
Create base error template
This commit is contained in:
parent
f49a54400e
commit
94d1f99344
|
@ -77,7 +77,7 @@ ROOT_URLCONF = "babybuddy.urls"
|
|||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [],
|
||||
"DIRS": ["babybuddy/templates/error"],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
{% extends 'babybuddy/page.html' %}
|
||||
{% load i18n widget_tweaks %}
|
||||
{% extends 'error/base.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}403 {% trans "Permission Denied" %}{% endblock %}
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<li class="breadcrumb-item active" aria-current="page">{% trans "Permission Denied" %}</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>403 {% trans "Permission Denied" %}</h1>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{% blocktrans trimmed %}
|
||||
You do not have permission to access this resource. Contact a site
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
{% extends 'babybuddy/base.html' %}
|
||||
{% load i18n widget_tweaks %}
|
||||
{% extends 'error/base.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}403 {{ title }}{% endblock %}
|
||||
|
||||
{% block breadcrumb_nav %}{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<div class="container mt-2 mt-lg-5">
|
||||
<div class="row justify-content-md-center">
|
||||
<div class="col-lg-12 mb-4">
|
||||
<div>
|
||||
{% block content %}
|
||||
<h1>403: {{ title }}</h1>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ main }} {{ reason }}
|
||||
|
@ -22,8 +18,4 @@
|
|||
with commas.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
{% extends 'error/base.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}404 {% trans "Page Not Found" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>404 {% trans "Page Not Found" %}</h1>
|
||||
<div>
|
||||
{% blocktrans trimmed with request_path=request_path %}
|
||||
The path <samp>{{ request_path }}</samp> does not exist.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -0,0 +1,14 @@
|
|||
{% extends 'babybuddy/base.html' %}
|
||||
{% load i18n widget_tweaks %}
|
||||
|
||||
{% block breadcrumb_nav %}{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<div class="container mt-2 mt-lg-5">
|
||||
<div class="row justify-content-md-center">
|
||||
<div class="col-lg-12 mb-4">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -8,7 +8,7 @@ from django.contrib.messages.views import SuccessMessageMixin
|
|||
from django.http import HttpResponseForbidden
|
||||
from django.middleware.csrf import REASON_BAD_ORIGIN
|
||||
from django.shortcuts import redirect, render
|
||||
from django.template import loader, TemplateDoesNotExist
|
||||
from django.template import loader
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import translation
|
||||
from django.utils.decorators import method_decorator
|
||||
|
@ -34,21 +34,21 @@ def csrf_failure(request, reason=""):
|
|||
Overrides the 403 CSRF failure template for bad origins in order to provide more
|
||||
userful information about how to resolve the issue.
|
||||
"""
|
||||
|
||||
print(reason == REASON_BAD_ORIGIN % request.META["HTTP_ORIGIN"])
|
||||
|
||||
if (
|
||||
"HTTP_ORIGIN" in request.META
|
||||
and reason == REASON_BAD_ORIGIN % request.META["HTTP_ORIGIN"]
|
||||
):
|
||||
c = {
|
||||
ccontext = {
|
||||
"title": _("Forbidden"),
|
||||
"main": _("CSRF verification failed. Request aborted."),
|
||||
"reason": reason,
|
||||
"origin": request.META["HTTP_ORIGIN"],
|
||||
}
|
||||
try:
|
||||
t = loader.get_template("error/403_csrf_bad_origin.html")
|
||||
return HttpResponseForbidden(t.render(c), content_type="text/html")
|
||||
except TemplateDoesNotExist:
|
||||
pass
|
||||
template = loader.get_template("error/403_csrf_bad_origin.html")
|
||||
return HttpResponseForbidden(template.render(ccontext), content_type="text/html")
|
||||
|
||||
return csrf.csrf_failure(request, reason, "403_csrf.html")
|
||||
|
||||
|
|
Loading…
Reference in New Issue