Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. views.py
  2. from django.shortcuts import render_to_response
  3. from django.contrib.auth import authenticate, login as auth_login
  4.  
  5. def login(request):
  6. msg = []
  7. if request.method == 'POST':
  8. username = request.POST['u']
  9. password = request.POST['p']
  10. user = authenticate(username=username, password=password)
  11. if user is not None:
  12. if user.is_active:
  13. auth_login(request, user)
  14. msg.append("login successful")
  15. else:
  16. msg.append("disabled account")
  17. else:
  18. msg.append("invalid login")
  19. return render_to_response('login.html', {'errors': msg})
  20.  
  21.  
  22. html
  23. <form action="/login/" method="post">
  24. Login:&nbsp; <input type="text" name="u">
  25. <br/>
  26. Password:&nbsp; <input type="password" name="p">
  27. <input type="submit" value="Login">
  28. </form>
  29. {% if errors %}
  30. <ul>
  31. {% for error in errors %}
  32. <li>{{ error }}</li>
  33. {% endfor %}
  34. </ul>
  35. {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement