开发者

How to print context content in the 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'd just like to print variable names available in the current context.

开发者_如何学C

Is there a way to do this without writing custom tag?


Use the Django debug toolbar - gives you this on the Templates tab, along a whole range of other useful debugging information.


If you use class-based views you can just give the current context like a variable to 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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜