Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

474
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda