"Authenticating Users" where should I put the code?

54 views
Skip to first unread message

Jack Yan

unread,
Mar 6, 2014, 9:45:04 AM3/6/14
to django...@googlegroups.com
in the tutorial and section "Authenticating Users":

where can I put code:
from django.contrib.auth import authenticate
user = authenticate(username='john', password='secret')
if user is not None:
    # the password verified for the user
    if user.is_active:
        print("User is valid, active and authenticated")
    else:
        print("The password is valid, but the account has been disabled!")
else:
    # the authentication system was unable to verify the username and password
    print("The username and password were incorrect.")
in what file or what folder?

Robin Lery

unread,
Mar 6, 2014, 11:12:57 AM3/6/14
to django...@googlegroups.com
This should be in your views.py.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0654812d-74d5-48a1-a977-26958f417a61%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Felipe Bessa Coelho

unread,
Mar 6, 2014, 11:13:26 AM3/6/14
to Django users
That is described later in the same page [1].

But if you just want to enable login/logout/password reset for your project, the easiest way is to include Django's default auth views in your urls.py [2].

[1] https://docs.djangoproject.com/en/1.6/topics/auth/default/#how-to-log-a-user-in
[2] https://docs.djangoproject.com/en/1.6/topics/auth/default/#module-django.contrib.auth.views

Jack Yan

unread,
Mar 6, 2014, 5:25:09 PM3/6/14
to django...@googlegroups.com
Thank you :)
Reply all
Reply to author
Forward
0 new messages