我有一个表单标签,我想有可变的内容。我向模板公开了一个名为outgroup的变量,我希望它包含在formfield标签中。我当前(不正确)的尝试如下:
{% formfield sent_amount label="How much do you want to send to a "+{{outgroup}} %}但这显然行不通。将变量放入label方法的正确方法是什么?
发布于 2019-09-10 20:54:45
你为什么不能在视野里做这样的事?
def study(request, studyID):
if request.method == 'GET' and request.user.is_authenticated:
form = ContactForm()
form.fields['from_email'].label = "{}, what's your email?".format(.get_full_name())使用form.fields["your_label_id"]设置它。
发布于 2020-04-02 19:00:36
当要插入标签中的动态内容是字符串而不是整数时,您只需要在引用动态变量后添加() (在下面的示例中,在self.player.type之后).如下所示:
FIRST go to pages.py:
class Contribute(Page):
form_model = 'player'
form_fields = ['type']
def vars_for_template(self):
return dict(
contribution_label='How many {} do you want to contribute?'.format(self.player.type())
)SECOND go to the relevant HTML page, Contribute.html
{% formfield player.contribution label=contribution_label %}https://stackoverflow.com/questions/57877945
复制相似问题