gpt4 book ai didi

Django help_text

转载 作者:行者123 更新时间:2023-12-03 18:10:54 24 4
gpt4 key购买 nike

我想在此表单中添加一些帮助文本。

class ItemForm(forms.ModelForm):
alternative_id = forms.CharField(max_length = 60, required = False, help_text = 'Valid wildcard search is in the format *XX, *XX*, XX*')

但是它不会出现在页面上。是不是因为我可能需要某个地方的模板标签?

编辑 : 我在我的模板里写了这个。
<div id="location_header">Search for Items</div>
<div id="form_container">
<form action="." method="post">
<fieldset class="model">
{{ form.as_p }}
{{ alternative_id.help_text }}
</fieldset>
<div id="form_footer">
<input type="submit" value="Search" >
</div>

</form>
</div>

帮助文本仍然没有出现。有没有办法编写帮助文本,同时允许 django 生成表单?

最佳答案

第 1 步。阅读:https://docs.djangoproject.com/en/1.8/topics/forms/#looping-over-the-form-s-fields

步骤 2. 自定义。这是规则。

Within this loop, {{ field }} is an instance of BoundField. BoundField also has the following attributes, which can be useful in your templates:

{{ field.label }} The label of the field, e.g. E-mail address.

{{ field.label_tag }} The field's label wrapped in the appropriate HTML tag, e.g. E-mail address

{{ field.html_name }} The name of the field that will be used in the input element's name field. This takes the form prefix into account, if it has been set.

{{ field.help_text }} Any help text that has been associated with the field.

{{ field.errors }} Outputs a containing any validation errors corresponding to this field. You can customize the presentation of the errors with a {% for error in field.errors %} loop. In this case, each object in the loop is a simple string containing the error message.

关于Django help_text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4792786/

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