How can I place sample text within a field of a django registration form.
Thank you in advance.
If you only want to insert a static text within the input that gives the user an idea of the structure that an email should have, it is enough to use the placeholder attribute that accepts a text string, which it will place in a soft tone text in said input
<input type="email" placeholder="ej: [email protected]" required>
If you want to show information to guide the user, you can do it from the model in this way, although keep in mind that it is not shown inside the input, but below
class Estudiante(models.Model):
nombre = models.CharField('Nombre', max_length=15, help_text="Escriba su nombre")
Using the forms provided by Django, these are defined in the file forms.py (by default, you can change the name) would be something like this more or less:
from django import forms
from django.forms import ModelForm
class RegisterForm(ModelForm):
class Meta:
model= TUMODELO
fields = ['email']
widgets = {
'comentario': forms.EmailInput(
attrs={'class': 'form-control','required': 'required', 'placeholder': 'ej: [email protected]'})
}
TUMODELO is your Registration model, the attribute fields
defines the fields of the model you want to include in your form and in widgets
is where you give form to the input that is then rendered in the template