Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

473
Vistas
How to validate data in django forms?

I have a feature on my website where a user can share content with another user registered on the site. They do this by entering in an email belonging to another user. This is then posted, setting the desired user to as a shared owner of content in the model.

What is the best way to check that the email address belongs to a registered user of the site?

Thanks!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think the efficient way is to search for the user with the given mail. Django User already has a mail field that is unique.

if you want to write from basic:

from django.core.validators import validate_email

class SampleForm(forms.Form):
    mail = forms.CharField(max_length=50)

    def clean(self):
        cleaned_data = super(SampleForm, self).clean()
        mail = cleaned_data.get('mail')
        # validate the structure of the mail address
        try:
            validate_email(mail)
        except validate_email.ValidationError:
            raise forms.ValidationError('email is not valid')
        # now find if mail has registered
        try:
            User.objects.get(email=mail)
        except User.DoesNotExist:
            raise forms.ValidationError('This mail address is not registered')
        return cleaned_data
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda