Skip to content

Instantly share code, notes, and snippets.

@chibiegg
Created January 18, 2014 06:04
Show Gist options
  • Save chibiegg/8486811 to your computer and use it in GitHub Desktop.
Save chibiegg/8486811 to your computer and use it in GitHub Desktop.
views.py
# encoding=utf-8
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import login
from django.shortcuts import redirect, render
def login_view(request):
if request.method == "POST":
form = AuthenticationForm(request.POST)
if form.is_valid():
user = form.get_user()
login(request, user)
return redirect("index")
else:
form = AuthenticationForm()
return render(request, "login.html", {"form":form})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment