You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix AttributeError in base.html when called without response_headers
This happens when using a `404.html` which extends DRF's `base.html` and is called by a `Resolver404`.
Since `Resolver404` goes via django's `handler404` and not via DRF's exception handling,
it doesn't get the extra context.
Since the `|items` filter doesn't check for `response_headers` being null (missing) it attempts
to call `<None>.items()`, thus raising an AttributeError.
Alternatives:
* This could alternatively be solved in the `items` filter, making it just check for null before continuing.
* If there was an easy way to delegate `handler404` etc to a DRF-based implementation which added the
correct context, that might be an ideal solution. I couldn't find an easy way to do this.
Copy file name to clipboardExpand all lines: rest_framework/templates/rest_framework/base.html
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -157,8 +157,8 @@ <h1>{{ name }}</h1>
157
157
</div>
158
158
159
159
<divclass="response-info" aria-label="{% trans "responseinfo" %}">
160
-
<preclass="prettyprint"><spanclass="meta nocode"><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %}{% for key, val in response_headers|items %}
<preclass="prettyprint"><spanclass="meta nocode"><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %}{% if response_headers %}{% for key, val in response_headers|items %}
0 commit comments