在Django模板中截取request.post返回的字符串

0 投票
1 回答
766 浏览
提问于 2025-04-18 12:47

我想在一个模板中截取由 request.post 返回的字符串:

比如说:

我访问了这个网址 /foo/bar/long/,现在

{% if request.path[:8] == '/foo/bar' %}...{endif}

应该是对的。

1 个回答

3

使用一个叫做 slice 的内置模板过滤器:

{% if request.path|slice:':8' == '/foo/bar' %}...{endif}

撰写回答