有没有办法在查看模板时使用/启动控制台(使用Django Debug Toolbar)?

有没有办法在查看模板时使用/启动控制台(使用Django Debug Toolbar)?

问题描述:

我喜欢 Django Debug Toolbar ,我主要使用它来查看传递的变量到模板(显示在右侧菜单的模板选项卡下)。

I love Django Debug Toolbar and I mainly use it just to see the variables passed to the template (shown under the "Templates" tab on the right menu).

但变量显示如下

{'form': <django.forms.models.OrderForm object at 0x1033937d0>}
{'csrf_token': <django.utils.functional.__proxy__ object at 0x103394cd0>}
{'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x103393510>,
 'user': <django.utils.functional.SimpleLazyObject object at 0x10339b690>}
{'debug': True, 'sql_queries': '<<sql_queries>>'}
{'LANGUAGES': '<<languages>>',
 'LANGUAGE_BIDI': False,
 'LANGUAGE_CODE': 'en-us'}
{'MEDIA_URL': ''}
{'STATIC_URL': '/static/'}
{'TIME_ZONE': 'EDT'}
{'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x10339bb90>}
{'request': '<<request>>'}

对于表单消息请求,这个列表不是很丰富。有没有办法深入挖掘并查看这些变量的所有可能的属性?类似于使用API​​ 使用

For variables like form, messages, and request, this list isn't very informative. Is there a way to dig deeper and view all the possible attributes for these kinds of variables? Kind of like playing with the API using python manage.py shell for templates?

你不可以使用 python manage.py shell 使用 django-debug-toolbar 执行此操作,但如果您安装 django-extensions ,您可以使用 runserver_plus 命令。这将使用werkzug调试器替换默认的异常/调试屏幕,这样可以访问交互式shell。

You can't do this with django-debug-toolbar but if you install django-extensions you can use the runserver_plus command. This replaces the default exception/debug screen with werkzug debugger which gives you access to an interactive shell.

检查在这里出一个教程