title: Adding a language field to the login template in Django
body: <p>I have to start a project in Django, which should be able to translate in three languages (Spanish, English and Italian).</p>
  <p>I have the 3 languages defined within the settings.py file, as it looks:</p>
  <pre><code>LANGUAGES = [
      ('es', _('Español')),
      ('en', _('English')),
      ('it', _('Italiano')),
  ]
  </code></pre>
  <p>My intention (I am not sure if it is the one indicated) is that when the user logs in, they enter their username, their password and the language with which they will work and from there the application establishes the menus, forms, etc. according to to the indicated language.</p>
  <p>My first approach was to extend the user model by incorporating a language field, as seen:</p>
  <pre><code>class User(AbstractUser):
      language = models.CharField(max_length=10,
                                  choices=settings.LANGUAGES,
                                  default=settings.LANGUAGE_CODE)
  
  </code></pre>
  <p>modifying the <em>AUTH_USER_MODEL</em> variable:</p>
  <pre><code>AUTH_USER_MODEL = 'usuarios.User'
  
  </code></pre>
  <p>and modify the login form, as it looks:</p>
  <pre><code>class LoginForm(ModelForm):
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          #self.fields['username'].widget.attrs['autofocus'] = True
  
      class Meta:
          model = User
          fields = 'username', 'password', 'language'
  
          widgets = {
              'username': forms.TextInput(
                  attrs={
                      'placeholder': 'Ingrese su username',
                  }
              ),
              'password': forms.PasswordInput(render_value=True,
                                              attrs={
                                                  'placeholder': 'Ingrese su password',
                                              }
                                              ),
              'language': forms.SelectMultiple(attrs={
                  'class': 'form-control select2',
                  'style': 'width: 100%',
                  'multiple': 'multiple'
              })
          }
  
  </code></pre>
  <p>As well as, add one more field to the login template:</p>
  <pre><code>&lt;div class=&quot;form-group form-primary&quot;&gt;
    {{form.username|add_class:'formcontrol'|attr:'type:text'}}
    &lt;span class=&quot;form-bar&quot;&gt;&lt;/span&gt;
    &lt;label class=&quot;float-label&quot;&gt;Usuario&lt;/label&gt;
  &lt;/div&gt;
  &lt;div class=&quot;form-group form-primary&quot;&gt;
    {{ form.password|add_class:'formcontrol'|attr:'type:password' }}
    &lt;span class=&quot;form-bar&quot;&gt;&lt;/span&gt;
    &lt;label class=&quot;float-label&quot;&gt;Contraseña&lt;/label&gt;
  &lt;/div&gt;
  &lt;div class=&quot;form-group form-primary&quot;&gt;
    {{ form.language|add_class:'formcontrol'|attr:'name:language'}}
    &lt;span class=&quot;form-bar&quot;&gt;&lt;/span&gt;
    &lt;label class=&quot;float-label&quot;&gt;Lenguaje&lt;/label&gt;
  &lt;/div&gt;
  
  </code></pre>
  <p>Despite the 3 actions mentioned, in the login I did not see the select with the available languages and the form.valid () did not work for me either.</p>
  <p>These are the login views. First use a class-based view:</p>
  <pre><code>class LoginFormView(LoginView):
      template_name = 'login.html'
  
      def dispatch(self, request, *args, **kwargs):
          if request.user.is_authenticated:
              return redirect(setting.LOGIN_REDIRECT_URL)
          return super().dispatch(request, *args, **kwargs)
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          context['title'] = 'Iniciar sesión'
          return context
  </code></pre>
  <p>And since it didn't work, then use a role-based view:</p>
  <pre><code>def user_login(request):
      if request.method == 'POST':
          form = LoginForm(request.POST)
          print(form.is_valid())
          if form.is_valid():
              cd = form.cleaned_data
              print(cd)
              user = authenticate(request, username=cd['username'], password=cd['password'])
              print(user)
              if user is not None:
                  if user.is_active:
                      login(request, user)
                      return HttpResponse('Authenticated successfully')
                  else:
                      return HttpResponse('Disabled account')
              else:
                  return HttpResponse('Invalid login')
      else:
          form = LoginForm()
      return render(request, 'login.html', {'form': form})
  
  </code></pre>
  <p>That is why I ask you if you can guide me in which would be the correct solution to my problem.</p>