>>> from django.contrib import auth
>>> user = auth.authenticate(username='john', password='secret')
>>> if user isnotNone:
... print"Correct!"... else:
... print"Invalid password."
deflogin_view(request): username = request.POST.get(‘username’, ‘’) password = request.POST.get(‘password’, ‘’) user = auth.authenticate(username=username, password=password) if user isnotNoneand user.is_active: # Correct password, and the user is marked “active” auth.login(request, user) # Redirect to a success page. return HttpResponseRedirect("/account/loggedin/") else: # Show an error page return HttpResponseRedirect("/account/invalid/")
from django.contrib.auth.views import login, logout
urlpatterns = patterns(’’, # existing patterns here… (r’^accounts/login/
′
<
/
s
p
a
n
>
,
l
o
g
i
n
)
,
(
<
s
p
a
n
c
l
a
s
s
=
"
h
l
j
s
−
s
t
r
i
n
g
"
>
r
′
a
c
c
o
u
n
t
s
/
l
o
g
o
u
t
/
'</span>, login), (<span class="hljs-string">r'^accounts/logout/
′</span>,login),(<spanclass="hljs−string">r′accounts/logout/’, logout), )