Skip to content

Instantly share code, notes, and snippets.

@yyl
Created June 28, 2012 17:47
Show Gist options
  • Select an option

  • Save yyl/3012813 to your computer and use it in GitHub Desktop.

Select an option

Save yyl/3012813 to your computer and use it in GitHub Desktop.
django built-in login demo
{% extends "base.html" %}
{% load url from future %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
urlpatterns = patterns('',
url(r'^$', 'testapp.views.home', name='home'),
url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'testapp/login.html'}),
url(r'^logout/$', 'django.contrib.auth.views.logout_then_login'),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
@login_required
def home(request):
return render_to_response('testapp/index.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment