我的Django模板使用if怎么了? [英] What is wrong with my Django templating use of if's?
问题描述
href ={%if:不在url.url%} http:// {%endif%} {{url.url}}> {{url.url}}< / a> ;
< span class =deleteid =URL _ {{url.id}}>& amp; amp;#10008;< / span> &安培; NBSP;
{%endfor%}
启发式用于预先添加部分或完整的网址,如google.com,假设有时人们会粘贴完整的浏览器网址,有时候人们会输入google.com,从不输入'http://'。
模板引擎抱怨{%if:not in url.url%}是无效的语法。这里有什么正确的语法/方法?
如何为此使用过滤器:
href ={{ulr.url | urlize}}
请记住在此之前检查以建立自己的(查找urlize):
https://docs.djangoproject.com/en/dev/ref/templates/builtins/
我认为一个更好的方法是将URL保存为管理员中的绝对URL,并在显示链接时显示 http:// ...
{% for url in urls %}
<a id="URL_url_{{ url.id }}" class="edit_rightclick"
title="RIGHT click to edit."
href="{% if ":" not in url.url %}http://{% endif %}{{ url.url }}">{{ url.url }}</a>
<span class="delete" id="URL_{{ url.id }}">&#10008;</span>
{% endfor %}
The heuristic is intended to prepend the value of a partial or complete URL like google.com, under the assumption that sometimes people will paste a full browser URL, and sometimes people will type out google.com and never type 'http://'.
The templating engine is complaining that '{% if ":" not in url.url %}' is invalid syntax. What is the correct syntax / approach here?
What about using a filter for this:
href="{{ ulr.url|urlize }}"
Remember to check here before to build your own (look for urlize): https://docs.djangoproject.com/en/dev/ref/templates/builtins/
I think a better approach would be to the save the URLs as absolute ones within the admin and strip "http://" when showing the link...
这篇关于我的Django模板使用if怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!