Django模板,如果基于当前URL值的标签 [英] Django template, if tag based on current URL value

查看:108
本文介绍了Django模板,如果基于当前URL值的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要能够根据当前网址值做一个if标签。例如,如果当前页面的url是

account / login / 然后不显示链接,而不从视图传递变量。



我不知道我可以如何写

解决方案

p>如果你将请求对象传递给你的模板,那么你可以使用这个:

  {% .get_full_path ==/ account / login /%} 


I want to be able to do an if tag based on the current URL value.

for example, if the current page's url is accounts/login/ then don't show a link, without passing a variable from the view.

I am not sure how I can write an {% if %} tag for this, is it possible?

解决方案

If you pass the "request" object to your template, then you are able to use this:

{% if request.get_full_path == "/account/login/" %}

这篇关于Django模板,如果基于当前URL值的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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