How to login a user in django
<p>I have a problem when I try to login a user to my website. I have a registration form, that when it's correctly filled redirects the user to a login page, where he can login. I save the user in the database, the class is called "Guest" not "User".</p>

<p>Here is the code for my models.py file:</p>

<pre><code>from django.db import models

# Create your models here.
class Guest(models.Model):
    name = models.CharField(blank = False, max_length = 100)
    surname = models.CharField(blank = False, max_length = 100)
    email = models.EmailField(blank = False, max_length = 200)
    guest_password = models.CharField(blank = False, max_length = 50)
    repeat_guest_password = models.CharField(blank = False, max_length = 50)
</code></pre>

<p>Here is the code for my forms.py file:</p>

<pre><code>from .models import Guest
from django import forms
from django.contrib import messages

class GuestForm(forms.ModelForm):
    class Meta:
        model = Guest
        fields = [
            'name',
            'surname',
            'email',
            'guest_password',
            'repeat_guest_password',
        ]

    def __init__(self, *args, **kwargs):
        super(GuestForm, self).__init__(*args, **kwargs)
        self.fields['name'].widget = forms.TextInput(attrs={
            'placeholder': 'Name*', 
            'required': True,
            'class': "form-first-name form-control"
            })

        self.fields['surname'].widget = forms.TextInput(attrs={
            'placeholder': 'Surname*',
            'required': True,
            'class': "form-last-name form-control"
            })

        self.fields['email'].widget = forms.EmailInput(attrs={
            'placeholder': 'Email*',
            'required': True,
            'class': "form-email form-control"
            })

        self.fields['guest_password'].widget = forms.PasswordInput(attrs={
            'placeholder': 'Enter password*',
            'required': True,
            'class': "form-first-name form-control"
            })

        self.fields['repeat_guest_password'].widget = forms.PasswordInput(attrs={
            'placeholder': 'Confirm password*',
            'required': True,
            'class': "form-first-name form-control"
            })

class AuthenticationForm(forms.Form):
    """
    Login form
    """
    email = forms.EmailField(widget=forms.widgets.TextInput)
    password = forms.CharField(widget=forms.widgets.PasswordInput)

    class Meta:
        fields = ['email', 'password']
</code></pre>

<p>Here is the code for my views.py file:</p>

<pre><code>from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth import authenticate, login

from .models import Guest
from .forms import GuestForm, AuthenticationForm

# Create your views here.

def guest_registration(request):
    form = GuestForm(request.POST or None)
    if form.is_valid():
        password1 = request.POST['guest_password']
        password2 = request.POST['repeat_guest_password']
        if Guest.objects.filter(email = request.POST['email']).exists():
            messages.error(request, 'That email address is already taken.', extra_tags='email_exists')
        elif len(request.POST['guest_password']) &lt; 6 or len(request.POST['guest_password']) &gt; 50:
            messages.error(request, 'Passwords must have minimum 6 and maximum 50 characters.', extra_tags='password_length_error')
        elif request.POST['guest_password'] != request.POST['repeat_guest_password']:
            messages.error(request, 'Passwords do not match.', extra_tags='passwords_dont_match_error')
        else:
            instance = form.save(commit = False)
            instance.save()
            form = GuestForm()
            messages.success(request, 'Registration was successfull, please log in.')
            return redirect('/login/')

    context = {
        "form": form,
    }

    return render(request, 'registrationpage.html', context)

def guest_login(request):
    """
    Login verification
    """

    if request.method == 'POST':
        form = AuthenticationForm(request.POST)
        if form.is_valid():
            guest = authenticate(email = request.POST['email'], password = request.POST['password'])
            if guest is not None:
                login(request, guest)
                return redirect('/to that users page/')
    else:
        form = AuthenticationForm()
    context = {
        "form": form,
    }

    return render(request, 'loginpage.html', context)
</code></pre>

<p>Here is the code for urls.py file from my 'guest' app:</p>

<pre><code>from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static

from .views import (
    guest_registration,
    guest_login,
    )

urlpatterns = [
    url(r'^registration/$', guest_registration),
    url(r'^login/$', guest_login),
    #url(r'^home/$', guest_registration),
]
</code></pre>

<p>How can I redirect he user, when he logs in successfully to his profile page, because it will be for every user different? 
And please can tell me why it wont login the user? Is my code correct?</p>

<p>Thank you in advance.</p>