2 回答

TA貢獻1878條經驗 獲得超4個贊
為什么你不能在視圖中做這樣的事情?
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"]設置。

TA貢獻1839條經驗 獲得超15個贊
當標簽中要插入的動態內容是字符串,而不是整數時,只需要在引用動態變量后(下例中self.player.type后)加上()……像這樣:
首先轉到 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())
)
第二次轉到相關的 HTML 頁面,Contribute.html
{% formfield player.contribution label=contribution_label %}
添加回答
舉報