example in field of registration form django

2

How can I place sample text within a field of a django registration form.

something like

Thank you in advance.

    
asked by user75960 26.03.2018 в 03:07
source

3 answers

6

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>
    
answered by 26.03.2018 / 03:14
source
3

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")
    
answered by 26.03.2018 в 04:12
3

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

    
answered by 26.03.2018 в 04:17