How do I get all the variables defined in a Django template?

前端 未结 4 1081
有刺的猬
有刺的猬 2021-01-30 12:51

I\'m new to Django and I wonder if there is a way to dump all the variables available to a template for debugging purposes. In Python I might use something like locals()<

4条回答
  •  不要未来只要你来
    2021-01-30 13:38

    Both Ned's and blaine's answers are good, but if you really want to achieve exactly what you ask for there's a template tag for it:

    {% debug %}

    Builtins:debug

    More information in the context_processor.debug including:

    If this processor is enabled, every RequestContext will contain debug and and sql_queries variables – but only if your DEBUG setting is set to True and the request’s IP address (request.META['REMOTE_ADDR']) is in the INTERNAL_IPS setting

    Similar to Peter G suggestion, I often use a

    {% debug|escape %}
    block at the end of the page that has display:none but that I can inspect to debug.

提交回复
热议问题