Is there a way to use/bring up a console when viewing templates (using Django Debug Toolbar)?

核能气质少年 提交于 2019-12-11 08:14:26

问题


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).

But the variables are shown like this

{'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>>'}

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?


回答1:


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.

Check out a tutorial here




回答2:


You can do this more efficiently using Django-Debug-Template: https://github.com/t0ster/django-debug-template

Just load template debugger by {% load debug %} first.

Then drop a shell from templates for a particular variable by {{ var|ipdb }}



来源:https://stackoverflow.com/questions/9902640/is-there-a-way-to-use-bring-up-a-console-when-viewing-templates-using-django-de

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!