# Django Custom Error Views
Prebuilt and customizable error views for Django.
* [Features](#features)
* [Installation](#installation)
* [Customizing Error Pages (Optional)](#customizing-error-pages)
* [Preview](#preview)
## Features
* Responsive design suitable for device sizes from mobile to desktop.
* Supports 400,403,404 and 500 HTTP errors by default.
* Minimal setup required to render the templates.
* Customizable error views through Django settings using custom error handlers.
## Installation
```sh
pip install django-custom-error-views
```
```python
INSTALLED_APPS = [
"django_custom_error_views",
]
```
That's all! Now Django will by default use the templates from the package for 400, 403, 404 and 500 pages. However, if you want to customize the pages by adding a logo, changing text etc. Then you'll need the next section as well.
### Customizing Error Pages
To customize the error pages you need to add a custom handler that injects context into the templates. Add the below snippet to your `urls.py`.
```py
from django.conf import settings
from django_custom_error_views.views import handler400 as ui_handler400
from django_custom_error_views.views import handler403 as ui_handler403
from django_custom_error_views.views import handler404 as ui_handler404
from django_custom_error_views.views import handler500 as ui_handler500
handler400 = "django_custom_error_views.views.handler400"
handler403 = "django_custom_error_views.views.handler403"
handler404 = "django_custom_error_views.views.handler404"
handler500 = "django_custom_error_views.views.handler500"
```
Add the below snippet to `urls.py` to debug and visualize the error pages locally. This is optional.
```py
# Optional
if settings.DEBUG:
# This allows the error pages to be debugged during development, just visit
# these url in browser to see how these error pages look like.
urlpatterns += [
path(
"400/",
ui_handler400,
kwargs={"exception": Exception("Bad Request!")},
),
path(
"403/",
ui_handler403,
kwargs={"exception": Exception("Permission Denied")},
),
path(
"404/",
ui_handler404,
kwargs={"exception": Exception("Page not Found")},
),
path("500/", ui_handler500),
]
```
And then you can add the following settings for each page.
```py
DJANGO_CUSTOM_ERROR_VIEWS = {
"company_logo": "/images/icon.png", # Static image or full URL
"400": {
"title": "Custom 400 error.",
"description": "Custom 400 description.",
"extra_content": "400 extras.",
},
"403": {
"title": "Custom 403 Error.",
"description": "Custom 403 description.",
"extra_content": "403 extras.",
"render_exception": True,
},
"404": {
"title": "Custom 404 Error.",
"description": "Custom 404 description.",
"extra_content": "404 extras.",
"render_exception": True,
},
"500": {
"title": "Custom 500 Error.",
"description": "Custom 500 description.",
"extra_content": "500 extras.",
},
}
```
Each option does the following:
* `company_logo` - Adds a company logo to the top of the page. Either a static (`{% static %}`) image or a full URL to an image
* `title` - Changes the title for the page to a custom one.
* `description` - Changes the description for the error to a custom one.
* `extra_content` - Adds extra text to the page below the title and description.
* `render_exception` - Renders the exception that occurred in the page (only for 403/404 pages), by default it's hidden.
## Preview
You can preview the error pages live at:
* [400 HTTP status code](https://hodovi.cc/400)
* [403 HTTP status code](https://hodovi.cc/403)
* [404 HTTP status code](https://hodovi.cc/404)
* [500 HTTP status code](https://hodovi.cc/500) - Has the status code 200 only in the demo.
Image preview:
![500-error](images/500-error.png)
Raw data
{
"_id": null,
"home_page": "https://github.com/adinhodovic/django-custom-error-views",
"name": "django-custom-error-views",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0.0",
"maintainer_email": "",
"keywords": "Django,Error,HTTP",
"author": "Adin Hodovic",
"author_email": "hodovicadin@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a4/5d/2e7b85c959adfa94a0f637bec83d79dc4d51091fe40a8b4c9eedbf5ddf58/django_custom_error_views-0.2.4.tar.gz",
"platform": null,
"description": "# Django Custom Error Views\n\nPrebuilt and customizable error views for Django.\n\n* [Features](#features)\n* [Installation](#installation)\n * [Customizing Error Pages (Optional)](#customizing-error-pages)\n* [Preview](#preview)\n\n## Features\n\n* Responsive design suitable for device sizes from mobile to desktop.\n* Supports 400,403,404 and 500 HTTP errors by default.\n* Minimal setup required to render the templates.\n* Customizable error views through Django settings using custom error handlers.\n\n## Installation\n\n```sh\npip install django-custom-error-views\n```\n\n```python\nINSTALLED_APPS = [\n \"django_custom_error_views\",\n]\n```\n\nThat's all! Now Django will by default use the templates from the package for 400, 403, 404 and 500 pages. However, if you want to customize the pages by adding a logo, changing text etc. Then you'll need the next section as well.\n\n### Customizing Error Pages\n\nTo customize the error pages you need to add a custom handler that injects context into the templates. Add the below snippet to your `urls.py`.\n\n```py\nfrom django.conf import settings\nfrom django_custom_error_views.views import handler400 as ui_handler400\nfrom django_custom_error_views.views import handler403 as ui_handler403\nfrom django_custom_error_views.views import handler404 as ui_handler404\nfrom django_custom_error_views.views import handler500 as ui_handler500\n\nhandler400 = \"django_custom_error_views.views.handler400\"\nhandler403 = \"django_custom_error_views.views.handler403\"\nhandler404 = \"django_custom_error_views.views.handler404\"\nhandler500 = \"django_custom_error_views.views.handler500\"\n```\n\nAdd the below snippet to `urls.py` to debug and visualize the error pages locally. This is optional.\n\n```py\n# Optional\nif settings.DEBUG:\n # This allows the error pages to be debugged during development, just visit\n # these url in browser to see how these error pages look like.\n urlpatterns += [\n path(\n \"400/\",\n ui_handler400,\n kwargs={\"exception\": Exception(\"Bad Request!\")},\n ),\n path(\n \"403/\",\n ui_handler403,\n kwargs={\"exception\": Exception(\"Permission Denied\")},\n ),\n path(\n \"404/\",\n ui_handler404,\n kwargs={\"exception\": Exception(\"Page not Found\")},\n ),\n path(\"500/\", ui_handler500),\n ]\n```\n\nAnd then you can add the following settings for each page.\n\n```py\nDJANGO_CUSTOM_ERROR_VIEWS = {\n \"company_logo\": \"/images/icon.png\", # Static image or full URL\n \"400\": {\n \"title\": \"Custom 400 error.\",\n \"description\": \"Custom 400 description.\",\n \"extra_content\": \"400 extras.\",\n },\n \"403\": {\n \"title\": \"Custom 403 Error.\",\n \"description\": \"Custom 403 description.\",\n \"extra_content\": \"403 extras.\",\n \"render_exception\": True,\n },\n \"404\": {\n \"title\": \"Custom 404 Error.\",\n \"description\": \"Custom 404 description.\",\n \"extra_content\": \"404 extras.\",\n \"render_exception\": True,\n },\n \"500\": {\n \"title\": \"Custom 500 Error.\",\n \"description\": \"Custom 500 description.\",\n \"extra_content\": \"500 extras.\",\n },\n}\n```\n\nEach option does the following:\n\n* `company_logo` - Adds a company logo to the top of the page. Either a static (`{% static %}`) image or a full URL to an image\n* `title` - Changes the title for the page to a custom one.\n* `description` - Changes the description for the error to a custom one.\n* `extra_content` - Adds extra text to the page below the title and description.\n* `render_exception` - Renders the exception that occurred in the page (only for 403/404 pages), by default it's hidden.\n\n## Preview\n\nYou can preview the error pages live at:\n\n* [400 HTTP status code](https://hodovi.cc/400)\n* [403 HTTP status code](https://hodovi.cc/403)\n* [404 HTTP status code](https://hodovi.cc/404)\n* [500 HTTP status code](https://hodovi.cc/500) - Has the status code 200 only in the demo.\n\nImage preview:\n\n![500-error](images/500-error.png)\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Prebuilt and customizable error views for Django.",
"version": "0.2.4",
"project_urls": {
"Documentation": "https://github.com/adinhodovic/django-custom-error-views",
"Homepage": "https://github.com/adinhodovic/django-custom-error-views",
"Repository": "https://github.com/adinhodovic/django-custom-error-views"
},
"split_keywords": [
"django",
"error",
"http"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4a85054a271def1d418a53967eff9bd6adf1958680088152d5091407a6bd6323",
"md5": "4c386569f05c8df146d60ce07e8204a0",
"sha256": "a97747cf4e41311658785def4ee7686b7c7b0be19de94240f064c5abea73b5de"
},
"downloads": -1,
"filename": "django_custom_error_views-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4c386569f05c8df146d60ce07e8204a0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0.0",
"size": 112920,
"upload_time": "2023-10-04T10:35:44",
"upload_time_iso_8601": "2023-10-04T10:35:44.542285Z",
"url": "https://files.pythonhosted.org/packages/4a/85/054a271def1d418a53967eff9bd6adf1958680088152d5091407a6bd6323/django_custom_error_views-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a45d2e7b85c959adfa94a0f637bec83d79dc4d51091fe40a8b4c9eedbf5ddf58",
"md5": "c2b6b5ce9a54f63f9026c6727196ebd2",
"sha256": "b5c0b8a9ff51c715324ab16f3b510075eb4811b0960f2746120514da544160b5"
},
"downloads": -1,
"filename": "django_custom_error_views-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "c2b6b5ce9a54f63f9026c6727196ebd2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0.0",
"size": 111095,
"upload_time": "2023-10-04T10:35:46",
"upload_time_iso_8601": "2023-10-04T10:35:46.357383Z",
"url": "https://files.pythonhosted.org/packages/a4/5d/2e7b85c959adfa94a0f637bec83d79dc4d51091fe40a8b4c9eedbf5ddf58/django_custom_error_views-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-04 10:35:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adinhodovic",
"github_project": "django-custom-error-views",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-custom-error-views"
}