Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- views.py
- from django.shortcuts import render_to_response
- from django.contrib.auth import authenticate, login as auth_login
- def login(request):
- msg = []
- if request.method == 'POST':
- username = request.POST['u']
- password = request.POST['p']
- user = authenticate(username=username, password=password)
- if user is not None:
- if user.is_active:
- auth_login(request, user)
- msg.append("login successful")
- else:
- msg.append("disabled account")
- else:
- msg.append("invalid login")
- return render_to_response('login.html', {'errors': msg})
- html
- <form action="/login/" method="post">
- Login: <input type="text" name="u">
- <br/>
- Password: <input type="password" name="p">
- <input type="submit" value="Login">
- </form>
- {% if errors %}
- <ul>
- {% for error in errors %}
- <li>{{ error }}</li>
- {% endfor %}
- </ul>
- {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement