94👍
There are several options (some of them already listed before):
-
django builtin debug tag – I use this boilerplate to display it properly:
<pre>
{% filter force_escape %}
{% debug %}
{% endfilter %}
</pre> -
Use django template debug application’s tags like attributes, variables and details or you can even set a breakpoint inside of a template where you can inspect everything with pdb debugger (or ipdb)
-
Django debug toolbar – has a template panel for this purpose
Usually all debug features work only when the app is in DEBUG mode.
- [Django]-What is a NoReverseMatch error, and how do I fix it?
- [Django]-Django: Fat models and skinny controllers?
- [Django]-Django: For Loop to Iterate Form Fields
20👍
Pro tip. Use textarea
and auto select onclick
for easier copy-paste:
<textarea onclick="this.focus();this.select()" style="width: 100%;"> {% filter force_escape %} {% debug %} {% endfilter %}</textarea>
- [Django]-Manager isn't accessible via model instances
- [Django]-How can I keep test data after Django tests complete?
- [Django]-Django South – table already exists
10👍
The debug toolbar does all this and much, much more. See the screencast for more. If you literally just want the variables, you could try
assert False, locals()
in your view
- [Django]-Invalid http_host header
- [Django]-"gettext()" vs "gettext_lazy()" in Django
- [Django]-Adding a user to a group in django
8👍
A slightly more complex solution with better rewards is to load django-debug-toolbar (documentation here)
There’s an option called ‘Templates’ with another option to ‘Toggle context’ and you can see all the variables passed to your template, as well as the ability to see the code behind the template.
- [Django]-Running a specific test case in Django when your app has a tests directory
- [Django]-Authenticate by IP address in Django
- [Django]-How to make two django projects share the same database
2👍
If you use pycharm of professional version, you can set breakpoints on some lines in a template file and view the variable value.
For more detail, follow this link.https://www.jetbrains.com/help/pycharm/debugging-django-templates.html
- [Django]-How can I return HTTP status code 204 from a Django view?
- [Django]-How to get an ImageField URL within a template?
- [Django]-How can I test https connections with Django as easily as I can non-https connections using 'runserver'?