title: Django: How to check if username already exists?
body: <p>I am not very advanced user of Django. I have seen many different methods online, but they all are for modified models or too complicated for me to understand.<br />
  I am reusing the <code>UserCreationForm</code> in my <code>MyRegistrationForm</code></p>
  <pre><code>class MyRegistrationForm(UserCreationForm):
  
      email = forms.EmailField(required=True)
  
      class Meta:
          model = User
          fields = ('username', 'email', 'password1', 'password2')
  
      def save(self, commit=True):
          user = super(MyRegistrationForm, self).save(commit=False)
          user.email = self.cleaned_data['email']
          user.set_password(self.cleaned_data[&quot;password1&quot;])
  
          if commit:
              user.save()
  
          return user
  </code></pre>
  <p>I struggle to understand or find a way to check if the username that user enters is already taken or not.
  So I just use this to redirect me to html where it says bad username or passwords do not match:</p>
  <pre><code>def register_user(request):
      if request.method == 'POST':
          form = MyRegistrationForm(request.POST)
          if form.is_valid():
              form.save()
  
              return HttpResponseRedirect('/accounts/register_success')
          else:
              return render_to_response('invalid_reg.html')
    
  
      args = {}
      args.update(csrf(request))
  
      args['form'] = MyRegistrationForm()
      print args
      return render_to_response('register.html', args)
  </code></pre>
  <p>Here is my registration template(if needed):</p>
  <pre><code>{% extends &quot;base.html&quot; %}
  
  {% block content %}
  
  &lt;section&gt;
  &lt;h2 style=&quot;text-align: center&quot;&gt;Register&lt;/h2&gt;
  &lt;form action=&quot;/accounts/register/&quot; method=&quot;post&quot;&gt;{% csrf_token %}
  
  &lt;ul&gt;
  {{form.as_ul}}
  &lt;/ul&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Register&quot; onclick=&quot;validateForm()&quot;/&gt;
  
  &lt;/form&gt;
  
  &lt;/section&gt;
  {% endblock %}
  </code></pre>
  <p>But I need to raise some kind of exception or something like that before user gets redirected. Maybe when user presses register they would get the error/warning saying that username is already taken. Is that possible?</p>