iTa*_*ayb 3 django django-templates
{% url form_entry %}我的模板中有一个标签,而form_entry值来自数据库.
如果网址无法解决,我会得到一个NoReverseMatch.如何在实际运行标记并获得异常之前检查标记是否成功?
就像是:
{% if resolvable form_entry %}
<a href="{% url form_entry %}">click here</a>
{% else %}
Sorry, not found.
{% endif %}
Run Code Online (Sandbox Code Playgroud)
使用标记as选项url.
{% url form_entry as the_url %}
{% if the_url %}
<a href="{{ the_url }}">click here</a>
{% else %}
Sorry, not found.
{% endif %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
82 次 |
| 最近记录: |