Comments (5)
You should read about handler500. You can very simply add a callable like this:
def handler500(request):
return TemplateResponse(request, '500.html', {'correlation_id': correlation_id.get()}, status=500)
where the 500.html contains the HTML you wish to render 👍
Please feel free to report back with a solution when you're done. Could be cool to add a generalised example to the docs 🙏
from django-guid.
Here's what worked for me
New config/error_views.py:
from django.http import (
HttpResponseBadRequest,
HttpResponseForbidden,
HttpResponseNotFound,
HttpResponseServerError,
)
from django_guid import get_guid
ERROR_PAGE_TEMPLATE = """
<!doctype html>
<html lang="en">
<head>
<title>%(title)s</title>
</head>
<body>
<h1>%(title)s</h1>
<p>%(details)s</p>
<p>Request ID: %(guid)s</p>
</body>
</html>
"""
def server_error(request):
return HttpResponseServerError(
ERROR_PAGE_TEMPLATE
% {
"title": "Server Error (500)",
"details": "An unexpected error occurred whilst processing the request",
"guid": get_guid(),
}
)
def permission_denied(request, exception, template_name="403.html"):
return HttpResponseForbidden(
ERROR_PAGE_TEMPLATE
% {
"title": "Permission Denied (403)",
"details": "No access to requested resource",
"guid": get_guid(),
}
)
def bad_request(request, exception, template_name="400.html"):
return HttpResponseBadRequest(
ERROR_PAGE_TEMPLATE
% {
"title": "Bad Request (400)",
"details": "",
"guid": get_guid(),
}
)
In config/urls.py add:
handler500 = "config.error_views.server_error"
handler403 = "config.error_views.permission_denied"
handler400 = "config.error_views.bad_request"
Would you be amenable to including the "default with guid" error handlers to the package?
from django-guid.
I'll leave that up to @JonasKs to decide, but I think adding template code to the library is a little out-of-scope. Think the styling etc. should be up to the user to define. Think it's a nice thing to describe how to set up in the docs though 👏
from django-guid.
Agree with @sondrelg 😊 Documentation PR very welcome, but I'd prefer not to maintain templates - styling is so different between everyone.
from django-guid.
I'll close this for now. If anyone else runs into similar issues, we now at least have your example to reference @andrew-cybsafe 👏
from django-guid.
Related Issues (20)
- [BUG] Can't add/override HTTP headers in other middlewares HOT 4
- IGNORE_URLS regex support HOT 2
- BSD-3-Clause, not BSD-4-Clause HOT 5
- Support Django 5 HOT 2
- Integration with Dramatiq HOT 1
- Integrate with django channels HOT 3
- Chore: Sentry scope migration fo 2.x
- [BUG] Sentry scope migration fo 2.x HOT 2
- Pass the GUID of a request to the Celery workers HOT 4
- Flask support HOT 3
- Elastic APM Integration HOT 1
- IGNORE_URL setting to opt-out for some URLs HOT 5
- Docs for Celery Integration and release HOT 1
- [BUG] - Missing CHANGELOG.rst from packaged tar.gz HOT 9
- Port celery support for django-guid 2.2 HOT 8
- Best way to pass on the correlation-id to child threads? HOT 8
- Full UUID as Text HOT 3
- v4 planning HOT 3
- [BUG] Overriding of "Access-Control-Expose-Headers" when HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-guid.