开发者

Django templating - listing available data to display

This is such a basic issue that I can only assume I'm looking at it completely the wrong way but...

I'm new enough to Django and I've taken the responsibility of redesigning a django application. The functionality is pretty good but the layout of things need to be styled and displayed a bit better.

My problem is this.

If in designing templates for for a PHP application and I want to see what attributes each of my objects have I can do a print_r (or a prettier inequivalent) and see exactly what data I can play with.

In django from the template level this doesn't appear to be possible which is baffling to me. Surely the idea of seperating design from busi开发者_运维知识库ness logic etc with MVC should also extend to have different people working on each level. If that is the case the a design person should have a way to display all variables available?


Use the django debug toolbar: http://github.com/robhudson/django-debug-toolbar

It requires minimal configuration after you install it and it will show you all kinds of useful information including the context for all the templates that were rendered, which is what you need.

To install it, in settings.py you put 'debug_toolbar', in INSTALLED_APPS and then add the following setting:

DEBUG_TOOLBAR_CONFIG = {
    'INTERCEPT_REDIRECTS': False,
    'SHOW_TOOLBAR_CALLBACK': lambda request: return DEBUG,
}

See the documentation for more details.

Once it is installed you should see a little tab DJDT on the right-hand side of your page. Clicking on it opens the toolbar and the template information is under Templates.


Django has a debug tag for this purpose.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜