【问题标题】:how to get argument in dictionary in django template?如何在 Django 模板的字典中获取参数?
【发布时间】:2013-05-15 17:21:50
【问题描述】:

我需要在 django 模板中使用 Balise 从一个视图传递到另一个视图,所以我有一个包含我的参数的字典 这是我在模板中使用的代码

{% for item in data % }
{% for key, value in item.items %}

{% if key == '13' %}<a href="{% url hisaccount value %}">{% endif %}<p>go to view</p></a>

{% endfor %}
{% endfor %}

但我收到此错误:

NoReverseMatch at /filter/

Reverse for '' with arguments '(1,)' and keyword arguments '{}' not found.

有什么建议吗?

【问题讨论】:

  • hisaccounturls.py 中是如何定义的?如果是 django 1.5,你可能需要做'hisaccount'
  • url(r'^hisaccount/(?P[-\w]+)/$','Our_MarketPlace.views.his_account', name='hisaccount'),
  • 哪个版本的 django ?
  • 问题是{% url hisaccount 没有成功解决。

标签: django templates url


【解决方案1】:

我需要做类似的事情。经过一番挖掘,看起来它没有作为默认的 Django 模板标签内置。

您需要自己构建,我使用了我在 stackoverflow 上找到的这个:Django template how to look up a dictionary value with a variable

【讨论】:

  • 这不是问题。他的 URL 没有正确解析。 dict 正在被正确评估
猜你喜欢
  • 2016-05-24
  • 2018-04-14
  • 2014-01-23
  • 2019-03-28
  • 1970-01-01
  • 1970-01-01
  • 2019-12-13
  • 2019-06-18
  • 2018-11-15
相关资源
最近更新 更多