Form to login

38 views
Skip to first unread message

Dariusz Mysior

unread,
Nov 4, 2015, 12:51:02 AM11/4/15
to Django users
I try do login view and I find it on

https://docs.djangoproject.com/en/1.8/topics/auth/default/

from django.contrib.auth import authenticate, login

def my_view(request):
   
username = request.POST['username']
   
password = request.POST['password']
   
user = authenticate(username=username, password=password)
   
if user is not None:
       
if user.is_active:
           
login(request, user)
           
# Redirect to a success page.
       
else:
           
# Return a 'disabled account' error message
           
...
   
else:
       
# Return an 'invalid login' error message.
       
...


to give request.POST username and password and username I must create my own form or maybe Django have that form ready? I use Django 1.8

Dheerendra Rathor

unread,
Nov 4, 2015, 1:54:20 AM11/4/15
to Django users

--
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/96258668-1c56-45d6-adce-59cff591dd23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

victor menezes

unread,
Nov 4, 2015, 11:08:55 AM11/4/15
to Django users
Looks like you are not making anything very custom on you view so maybe would be easier/better to use the buitin views from django auth.

on your urls.py you can do:

from django.contrib.auth import views as auth_views

urlpatterns = [
    ...
    url(r'^login/', auth_views.login),
]

On your settings.py:
LOGIN_URL = '/login' #the global address of the login page(loguin_required decorators, etc will redirect to here)
NEXT_PAGE = '/home' #page the user is redirected after login

Dariusz Mysior

unread,
Nov 5, 2015, 2:31:12 PM11/5/15
to Django users
Thank's I have it!
Reply all
Reply to author
Forward
0 new messages