简体   繁体   English

仅替换web.py模板中的一个变量

[英]replace only one variable in web.py templates

I am passing variable to template in web.py and have the same condition in some places. 我正在将变量传递给web.py中的模板,并且在某些地方具有相同的条件。 Like this: 像这样:

$if myvar=="string1": $ if myvar ==“ string1”:

$passed argument1

............ ............

$if myvar =="striung2": $ if myvar ==“ striung2”:

$passed argument2

If say myvar is "string1" and I pass passed = "AAA" then I have AAA argument1 on my page, but the other if statements get replaced by empty string? 如果说myvar是“ string1”,并且我传递的传递是“ AAA”,那么我的页面上有AAA参数1,但是另一个if语句被空字符串替换了吗?

How to avoid that? 如何避免呢? Ie how to leave other statements intact? 即如何保留其他陈述不变?

Your question is unclear. 您的问题不清楚。 What are you trying to do? 你想做什么? It sounds like you just need to use else: 听起来您只需要使用else即可:

if myvar == "string1":
  print passed
else:
  # something

But it's very hard to understand what you are asking. 但是很难理解您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM