我希望能够根据当前的URL值执行if标记.
例如,如果当前页面的url accounts/login/不显示链接,则不从视图中传递变量.
我不知道如何{% if %}为此写一个标签,这可能吗?
nim*_*smi 50
您还可以使用以下命令为动态网址执行此操作:
{% url 'show_user_page' user=user as the_url %}
{% if request.get_full_path == the_url %}something{% endif %}
Run Code Online (Sandbox Code Playgroud)
您的urls.py包含以下内容:
(r'^myapp/user/(?P<user>\d+)/$', 'show_user_page'),
Run Code Online (Sandbox Code Playgroud)
我知道这是因为当我在文档中找到答案时,我花了很多时间起草了stackoverflow问题.
我会说,即使在简单的情况下,这可能是更好的方法,因为它更松散耦合.
Gab*_*oss 27
如果将"request"对象传递给模板,则可以使用:
{% if request.get_full_path == "/account/login/" %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17044 次 |
| 最近记录: |