title: How can i checking username and mail exists in Django
body: <p>I just started learn Django. I made a registration form. its working good. But I couldn't check exists usernames and mails in this registration form. if i try registers with the same username, I get the (1062, "Duplicate entry 'asdasd' for key 'username'") error. (asdasd my username..)</p>
  
  <p>How can I solve this?</p>
  
  <p>forms.py</p>
  
  <pre><code>from django import forms
  class RegisterForm(forms.Form):
      username = forms.CharField(required=True, max_length=20, label= "Kullanıcı Adı")
      email = forms.EmailField(required=True, label="E-Mail")
      password = forms.CharField(max_length=20, label= "Password", widget=forms.PasswordInput)
      confirm = forms.CharField(max_length=20, label="RePassword",widget=forms.PasswordInput)
  def clean(self):
      username = self.cleaned_data.get("username")
      email = self.cleaned_data.get("email")
      password = self.cleaned_data.get("password")
      confirm = self.cleaned_data.get("confirm")
  
  
      if password and confirm and password != confirm:
          raise forms.ValidationError("Passwords dont match")
  
      values = {
          "username" : username,
          "email" : email,
          "password" : password,
      }
      return values
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.shortcuts import render, redirect
  from .forms import RegisterForm
  from django.contrib import messages
  from django.contrib.auth.models import User
  from django.contrib.auth import login
  
  
  def register(request):
  
      form = RegisterForm(request.POST or None)
  
      if form.is_valid():
          username = form.cleaned_data.get("username")
          email = form.cleaned_data.get("email")
          password = form.cleaned_data.get("password")
          newUser = User(username=username)
          newUser.email = email
          newUser.set_password(password)
          newUser.save()
          login(request, newUser)
          messages.success(request,"Successful on Register")
          return redirect("index")
      context = {
          "form": form
      }
      return render(request, "register.html", context)
  
  
  def loginUser(request):
      return render(request, "login.html")
  
  def logoutUser(request):
      return render(request, "logout.html")
  </code></pre>
  
  <p>Thank you so much!</p>