English 中文(简体)
django模板,根据关键标准获得字塔价值
原标题:django templates accessing a dict value based on key

in my views.py i obtain 5 dicts, which all are something like {date:value} all 5 dicts have the same length and in my template i want to obtain some urls based on these dicts, with the common field being the date - as you would do in an sql query when joining 5 tables based on a common column

在座各位想:

for key, value in loc.items():
    print key, loc[key], ctg[key], sctg[key], title[key], id[key]

但是,在干jan的模板中,可以做到的是:

{% for lock, locv in loc.items %}
    {% for ctgk, ctgv in ctg.items %}
        {% for subctgk, subctgv in subctg.items %}
            {% for titlek, titlev in titlu.items %}
                {% for idk, idv in id.items %}

                          {% ifequal lock ctgk %}
                            {% ifequal ctgk subctgk %}
                                {% ifequal subctgk titlek %}
                                    {% ifequal titlek idk %}

                                    <br />{{ lock|date:"d b H:i" }} - {{ locv }} - {{ ctgv }} - {{ subctgv }} - {{ titlev }} - {{idv }}
                                     .... {% endifequals & endfors %}

当然,哪一个时候了,需要很多时间才能作出。

现在,我正在研究如何建立一个习俗标签,但我不知道你们是否对这个议题有任何反馈?

问题回答

象你这样,我需要使用的是非一致的法令。 • 如何dict小阶层,包括你想要的东西:

class MyThing:
  def __init__(self, loc, ctg, sctg, title, id):
    self.loc = loc
    self.ctg = ctg
    self.sctg = sctg
    self.title = title
    self.id = id

这是否使你的模板更加痛苦? (如果我误解了问题,我会说,在你打下了<条码>。

Django模板应当尝试作为字典研究(如果是字典)解决变数。 http://code>ctg.key equals to ctg[key]。 您:

{% for key, value in loc.items %}
  {{ key|date:"d b H:i" }} - {{ value }} - {{ ctg.key }} - {{ subctg.key }} - {{ title.key }} - {{ id.key }}




相关问题
Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

How to create a submit button template in Oracle APEX?

I m trying to create a template for a button in Oracle APEX but I don t seem to have access to the appropriate substitution strings to make it work. For non-templated buttons APEX seems to insert a ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Load ruby on rails template from database

I wonder if there is a way for me to store ruby on rails view files into database store and have that fetched directly from there. The reason is I want to create a CMS with all the user data stored in ...

Templated HTML Editor

I m looking for a HTML editor that kinda supports templated editing or live snippets or something like that. Background: I m working on a website for a friend. As there are no specifications what the ...

Dreamweaver changing path to site s reference instead of local

I have noticed recently, when I apply a template to a new HTML website, all the relative paths are pointed to my local files, example: file:///C|/webstuff/files but I cannot set them to relative paths ...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...

热门标签