0
I created a customer registration form and in the meta class I declared the Fields and their respective Abels. However the label 'CPF' referring to the field 'n_cpf' does not show on the page, only appears N Cpf. How do I label 'CPF' in this field?
Forms.py:
from django import forms
from .models import Cliente
from localflavor.br.forms import BRCPFField
class ClienteForm(forms.ModelForm):
n_cpf = BRCPFField()
class Meta:
model = Cliente
fields = ['name', 'last_name', 'n_cpf', 'birth_date', 'height', 'weight', 'active']
labels = {'name': 'Nome',
'last_name': 'Sobrenome',
'n_cpf': 'CPF',
'birth_date': 'Data de nascimento',
'height': 'Altura',
'weight': 'Peso',
'active': 'Ativo',
}
html register.:
{% extends 'app_web/base.html' %}
{% block content %}
<p>Adicione um novo cliente:</p>
<form action="{% url 'app_web:novo_cliente' %}" method="POST">
{% csrf_token %}
{{ form.as_p }}
<button name="submit">Adicionar</button>
</form>
{% endblock content %}
Could you show the html page where the form is being displayed? Note that you can display the label by typing in html, for example {{ form.cpf.label_tag }}
– Victor Fernandes
OK friend put the html. I’m starting in Django, in the html form I use only this double bracket '{{ }}' to interpolate the variable.
– at8819