[Django]-How can I debug "Exception while resolving variable in template 'unknown'"?

1πŸ‘

The point wasn’t variable lastframe or variable exception_type you gotta checkout your url, all of the urls, not just back-end url but also the front-end url.
Check out the front-end urls and middleware (if you wrote your own middleware files, the best check way is testing admin on your url).
I got the same kind of question, when I checked url and middleware, I solved the issue easily.

πŸ‘€dream-blue

1πŸ‘

If you are developing your Django project using vscode with the vscode-python extension you can debug your template files as below

Try to inspect your variable in debug console for example i have entered switch_data variable coming from my view

Vscode Django Template Debug View

1πŸ‘

you just have to check the url first both the back-end and front-end.

πŸ‘€Ayush Saini

1πŸ‘

One of the variables in your code is faulty. I cannot see the code so I do not know which one. Exeption_type likely refers to a type of variable in your code or an exception to one variable via another. However, it is also possible that there is another file referenced in your code that contains a common mistake, such as forgetting to define it as global().

πŸ‘€Andrew

1πŸ‘

Jinja2:

from jinja2 import Environment, FileSystemLoader

env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('example_template.html')

# Make sure the variable is defined in the context dictionary
rendered_template = template.render(variable_name=variable_value)

Django

from django.template import Context, Template

with open('example_template.html', 'r') as template_file:
    template = Template(template_file.read())

# Make sure the variable is defined in the context dictionary
context = Context({"variable_name": variable_value})
rendered_temp

late = template.render(context)

Leave a comment