Advertisement
lewapkon

django.contrib.auth

Oct 20th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. urlpatterns = patterns('',
  2.     #...
  3.     url(r'^login/$', 'django.contrib.auth.views.login',
  4.         {'template_name': 'workshops/login.html'}, name='login'),
  5.  
  6.     url(r'^logout/$', 'django.contrib.auth.views.logout',
  7.         name='logout'),
  8.     #...
  9. )
  10.  
  11. template:
  12.     <form class="form-signin" role="form" method="post" action="{% url 'django.contrib.auth.views.login' %}">
  13.         {% csrf_token %}
  14.         {% if form.errors %}
  15.             <p class="warning">The username or password you entered is incorrect.</p>
  16.         {% endif %}
  17.         <h2 class="form-signin-heading">Sign in</h2>
  18.         {{ form.username | add_class:'form-control' | attr:'placeholder:Username' | attr:'required autofocus' }}
  19.         {{ form.password | add_class:'form-control' | attr:'placeholder:Password' | attr:'required' }}
  20.         <button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
  21.     </form>
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.                     {% if user.is_authenticated %}
  33.                         Logged in as: <a href="{% url 'person' user.username %}">{{ user.person }}</a>
  34.                     </li>
  35.                     <li>
  36.                         <a href="{% url 'logout' %}?next={% url 'workshops' %}">Logout</a>
  37.                     {% else %}
  38.                         <a href="{% url 'login' %}">Login</a>
  39.                     {% endif %}
  40.                     </li>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement