gpt4 book ai didi

django - 如何在 Django 中翻译表单

转载 作者:行者123 更新时间:2023-12-04 06:04:41 24 4
gpt4 key购买 nike

我在 Django 站点中有一个表单

<form method="POST" action="." class="right_custom">{% csrf_token %}
<br>{% trans "Enter the discount coupon code if you have any" %}</br>
<input type="text" name="coupon_code" size="25" maxlength="25" />
<input type="submit" name="submit" value="Caluclate Discount"/>
</form>

我想将整个网站翻译成多种语言。我需要翻译按钮文本 Caluclate Discount .我怎样才能做到这一点?如果我使用 {% trans %}标签, View 将如何捕获正确的发布请求?

更新

同一个页面上有很多这样的表单,我的 View 使用 if postdata['submit']=="Caluclate Discount"以确定它是哪个提交请求。

最佳答案

我能够让翻译工作。

感谢@linux-warrior 和@Joachim 的回答

现在的形式是

<form method="POST" action="." class="right_custom">{% csrf_token %}
<input type="hidden" name="form_name" value="discount_form" />
<br>{% trans "Enter the discount coupon code if you have any" %}</br>
<input type="text" name="coupon_code" size="25" maxlength="25" />
<input type="submit" name="submit" value="{% trans "Caluclate Discount" %}" />
</form>

我检查是否 postdata['form_name']=='discount_form'在我看来

关于django - 如何在 Django 中翻译表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8500862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com