How to print contextual content in a template?

How can I print or iterate over all the variables available in the context from the template code?

I know about {% debug %} , but it contains too much information. I would just like to print the variable names available in the current context.

Is there any way to do this without writing a special tag?

+4
source share
2 answers

Use the Django debug toolbar β€” you'll find this on the Templates tab across the entire spectrum of other useful debugging information.

+8
source

If you use class-based views, you can simply specify the current context as a variable in the context:

 class MainView(TemplateView): template_name = 'base.html' def get_context_data(self, **kwargs): ctx = super(MainView, self).get_context_data(**kwargs) ctx['ctx'] = ctx return ctx 

How can you access the context with {{ctx}}

+2
source

All Articles