fix: Update how we render the error pages.

We were adding paths for the error pages in two places so one of them
simply wasn't being used. The lms urls.py also covered the 429 wich the
static_templates_view urls.py did not cover.  We don't need both and we
need the definition of the handlerNNN variables in urls.py to override
the default django error views so I'll leave just those.

I also made the `exception` parameter for the `render_404` function
optional by adding a default value.  We don't use the exception when
rendering the 404 page but the exception argument is a part of the
default method signature for the function that `render_404` replaces so
I didn't want to remove it and cause issues when django tries to call
this function.
This commit is contained in:
Feanil Patel
2023-06-13 11:25:11 -04:00
parent 45efafb07a
commit 0326b45d6a
3 changed files with 3 additions and 7 deletions

View File

@@ -9,12 +9,6 @@ from django.urls import path, re_path
from lms.djangoapps.static_template_view import views
urlpatterns = [
# Semi-static views (these need to be rendered and have the login bar, but don't change)
path('404', views.render, {'template': '404.html'}, name="404"),
# display error page templates, for testing purposes
path('404', views.render_404, name='static_template_view.views.render_404'),
path('500', views.render_500, name='static_template_view.views.render_500'),
path('blog', views.render, {'template': 'blog.html'}, name="blog"),
path('contact', views.render, {'template': 'contact.html'}, name="contact"),
path('donate', views.render, {'template': 'donate.html'}, name="donate"),

View File

@@ -106,7 +106,7 @@ def render_403(request, exception=None):
@fix_crum_request
def render_404(request, exception): # lint-amnesty, pylint: disable=unused-argument
def render_404(request, exception=None): # lint-amnesty, pylint: disable=unused-argument
request.view_name = '404'
return HttpResponseNotFound(render_to_string('static_templates/404.html', {}, request=request))

View File

@@ -214,6 +214,8 @@ urlpatterns = [
),
path('api/discounts/', include(('openedx.features.discounts.urls', 'openedx.features.discounts'),
namespace='api_discounts')),
# Provide URLs where we can see the rendered error pages without having to force an error.
path('403', handler403),
path('404', handler404),
path('429', handler429),