Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

472
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!