Opened 7 years ago
Last modified 23 hours ago
#29446 assigned New feature
Include template context in error page when relevant
Description ¶
When an error is encountered while rendering a template (in Debug mode), Django helpfully displays the template source, followed by the usual stack-trace with local variable values. It could be useful to also include the template context at the point of the error, as these are often the relevant "local variables".
While the context is actually often available as a local variable in one of the function calls close to the bottom of the stack trace, it is not obvious, and requires a somewhat tedious search (there are usually a series of calls taking a context
variable, most of them irrelevant).
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.
Change History (14)
comment:1 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 7 years ago
comment:3 by , 6 years ago
Hi Shai Berger,
Could you give some more information about this feature request?
It would be nice to have some example of error page you would like to see.
If anyone else has any idea what the expected error page should look like, please comment.
comment:4 by , 6 years ago
Cc: | added |
---|
comment:5 by , 5 years ago
Cc: | added |
---|
comment:6 by , 2 weeks ago
Owner: | set to |
---|---|
Status: | new → assigned |
follow-up: 8 comment:7 by , 2 weeks ago
Hi, I am bhupesh Panwar, i recently reproduce this issue.I have understand the issue very well. So i have a solution that can we create an middleware.py file that logs template context when error happens
follow-up: 11 comment:8 by , 12 days ago
First of all, I apologize for missing the calls for more details all these years ago.
Somehow, I only saw them now.
Second,
Replying to Bhupesh panwar:
So i have a solution that can we create an middleware.py file that logs template context when error happens
I think it would be more helpful to put the context in the error page with all the other relevant info, but if you can pick the right context and put it in the log, then IMO:
- It's a good first step towards putting it on the page
- It's already helpful in and of itself
comment:9 by , 12 days ago
Has patch: | set |
---|
comment:11 by , 11 days ago
Replying to Shai Berger:
Thank you for reply, Shai, I have already raise an pr.if there might be some issue. i will keep you posted
comment:12 by , 10 days ago
Patch needs improvement: | set |
---|
comment:13 by , 29 hours ago
I created a new pull request because my previous one had some issues. Here is the link: https://github.com/django/django/pull/19282 .
The issue is about retrieving the context (dictionary) from the user's views.py. However, I couldn't find a way to retrieve the context from views.py since the context variable name can vary depending on the user.
To illustrate this, I created a context.py file as an example. Could you suggest how we can dynamically retrieve the context variable from views.py?
comment:14 by , 23 hours ago
Has patch: | unset |
---|---|
Patch needs improvement: | unset |
Shai,
Can you elaborate on what you mean? Are you suggesting we put the local context variables in a special section instead of with the rest of the local variables?