简体   繁体   English

Jinja模板Flask中的多个参数

[英]Multiple Arguments in Jinja templates Flask

I have 4 different types of subscription packages and I need to set template in a way that if one subscription is active than other enrol buttons should be disabled. 我有4种不同类型的订阅包,我需要以一种方式设置模板:如果一个订阅处于活动状态,则应该禁用其他注册按钮。 I have two variables to work with. 我有两个变量要处理。

is_active=True 
subs_type = 'yearly' or 'monthly' or 'quarterly' or 'weekly'

On my packages.html page I have 4 packages like: 在我的packages.html页面上,我有4个程序包,例如:

<div>
<h1>Package 1</h1>
<a href="/someurl"><input class"btn" type="submit" value="enroll"></a>
</div>
<div>
<h1>Package 2</h1>
<a href="/someurl"><input class"btn" type="submit" value="enroll"></a>
</div>
<div>
<h1>Package 3</h1>
<a href="/someurl"><input class"btn" type="submit" value="enroll"></a>
</div>
<div>
<h1>Package 4</h1>
<a href="/someurl"><input class"btn" type="submit" value="enroll"></a>
</div>

I have few conditions to apply which I couldn't make work together. 我没有什么条件可以申请,我无法共同努力。 1. If user subscribed one of the package then all other enrol button should pop message that he/she already subscribed. 1.如果用户订阅了软件包中的一个,则所有其他注册按钮应弹出消息,表明他/她已经订阅了。 2. The one that is subscribed should sow cancel button but rest should show enrol button but should work. 2.订阅的那个应该播下取消按钮,其余的应该显示注册按钮但是应该可以。

Can someone help me to make it work please? 有人可以帮我使它工作吗?

Considering what you said in that comments. 考虑您在那条评论中所说的话。 That is_active defines if the client is already subscribed, and package_type describes which package the client is subscribed to. is_active定义了客户端是否已经订阅,而package_type描述了客户端订阅了哪个包。

So let's say that package 1 is the yearly package, then: 因此,假设套件1是年度套件,那么:

<h1>Package 1</h1>
{% if is_active %}
    {% if package_type == "yearly" %}
    <a href="/someurl"><input class"btn" type="submit" value="cancel"></a>
    {% else %}
    already enrolled to another package
    {% endif %}
{% else %}
<a href="/someurl"><input class"btn" type="submit" value="enroll"></a>
{% endif %}

Assuming you're using jinja and not another templating language. 假设您使用的是Jinja,而不是另一种模板语言。

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

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