我是django的新手,正在尝试仅渲染其中没有单词“ After”或“ Before”的文本。但这没有破坏任何东西,但实际上没有删除那些值吗?
我看过使用正则表达式,但实际上不建议在Django模板中使用。
{% if "After" not in window.name or "Before" not in window.name %}
{{window.event_id}}-{{window.name}}
{% endif %}
我正在使用的代码库几乎不可能在您进入模板之前在模型中删除这些值...我只为维护和忍受这道歉!
答案 0 :(得分:1)
问题在于您的情况永远都是真的。
这是一种方法。可能不是最理想的。
widget: .!panedwindow.!panedwindow2.!frame.!frame.!button
253330600Open_Selector
str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.
这样,仅当字符串中没有“ Before”或“ After”时才打印。我没有测试此代码,但希望您能理解。