开发者

Django want to display only title

Hello I have {{order}}In my template. This displays all storage items. When I run the server, it shows up like this.

[<StorageItem: my item>, <StorageItem: Another Item>]

Only really want those items. I don't want it to disp开发者_如何转开发lay StorageItem or the brackets.


The brackets means its a list of items.

You can iterate:

{% for o in order %}
    {{ o }}
{% endfor %}

Or use the join filter: {{ order|join:", " }} http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#join

As for what you want to display, I can't tell without knowing what you want!

What do you want it to display instead of StorageItem?

What's shown when you simply call {{ o }} in a template is defined in your model __unicode__ method.
http://docs.djangoproject.com/en/dev/ref/models/instances/#unicode

If it's specific field, you could just type {{ o.myfield }}


What you currently have, is a list of objects. Well, you will need to iterate over the list then. {{ order }} isn't really an appropriate name though, it should be {{ orders }}

{% for order in orders %}
  {{ order }}
{% endfor %}


Then iterate through the list with {% for %} and display each item.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜