django中的{%url url_name%}和{%url'url_name'%}之间有什么区别? [英] what is the difference between {% url url_name %} and {% url 'url_name' %} in django

查看:583
本文介绍了django中的{%url url_name%}和{%url'url_name'%}之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道{%url url_name%}和{%url'url_name'%}之间有什么区别。为什么会有这样的差异?什么时候用什么?需要一些澄清...谢谢..

I am not sure what is the difference between {% url url_name %} and {% url 'url_name' %}. Why is there such a difference. When to use what? Need some clarification on that... Thanks..

推荐答案

截至django 1.5 {%url url_name %} 将该参数视为上下文变量,而 {%url'url_name'%} 将为您提供名为url_name的URL。在以前的版本中,后一种语法是错误的,不行。

As of django 1.5 {% url url_name %} would treat the argument as a context variable, whereas {% url 'url_name' %} would give you the url named 'url_name'. In prior versions, the latter syntax is wrong, and won't work.

这篇关于django中的{%url url_name%}和{%url'url_name'%}之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆