我正在处理 https://bixly.com/blog/awesome-forms-django-crispy-forms/ 中介绍的内容,尝试使用 Django Crispy Forms 设置 Bootstrap 3 表单。在 app1/models.py 中,我已经设置好了我的表单:
在app1/forms.py中,我有以下内容:
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser
from django import forms
class User(AbstractUser):
# Address
contact_name = models.CharField(max_length=50)
contact_address = models.CharField(max_length=50)
contact_email = models.CharField(max_length=50)
contact_phone = models.CharField(max_length=50)
......
在app1/forms.py中,我有以下内容:
class UserForm(forms.ModelForm):
class Meta:
model = User # Your User model
fields = ['contact_name', 'contact_address', 'contact_email', 'contact_phone']
helper = FormHelper()
helper.form_method = 'POST'
helper.add_input(Submit('Submit', 'Submit', css_class='btn-primary'))
现在,标签与字段名称相同。我该如何将标签设置为其他内容?例如,对于“contact_name”,标签可能会问“你叫什么名字?”