title: How can I get self.fields element value in forms file?
body: <p>In my <code>forms.py</code> file I have method called <code>r_valid</code> and it is used in views.py file.</p>
  <pre><code>from django.shortcuts import render, redirect
  from .forms import UserRegisterForm
  from django.contrib import messages
  
  def register(request):
      if request.method == 'POST':
          form = UserRegisterForm(request.POST)
          if form.is_valid():
              form.r_valid()
              form.save()
              username = form.cleaned_data.get('username')
              messages.success(request, f'Created Account for {username}!')
              return redirect('main')
      else:
          form = UserRegisterForm()
  
      context = {
          'form': form,
      }
      return render(request, 'register.html', context)
  </code></pre>
  <p>The meaning of it is to ad few more barriers for user which is creating an account. The problem is that in browser it returns an error =&gt;</p>
  <pre class="lang-none prettyprint-override"><code>TypeError at /register/
  'CharField' object is not subscriptable
  </code></pre>
  <p>Here you can see that problem is that I can't get <code>self.fields['username']</code>. So please explain how can I get the username value.</p>
  <pre><code>from django import forms
  from django.contrib.auth.models import User
  from django.contrib.auth.forms import UserCreationForm
  from django.core.exceptions import ValidationError
  
  class UserRegisterForm(UserCreationForm):
      email = forms.EmailField()
  
      class Meta:
          model = User
          fields = ['username', 'email', 'password1', 'password2']
  
      def r_valid(self):
          j = self.fields['username']
  
          if j[0] in '0123456789':
              raise ValidationError('The username can\'t start with number')
          
          if len(j) &lt; 6:
              raise ValidationError('That username is too short')
  
          for c in j:
              if c in '@+-/':
                  raise ValidationError('Your username can\'t contain @, +, - or /')
      
      def __init__(self, *args, **kwargs):
          super(UserRegisterForm, self).__init__(*args, **kwargs)
          self.fields['username'].help_text = ''
  </code></pre>