Created
June 28, 2012 17:47
-
-
Save yyl/3012813 to your computer and use it in GitHub Desktop.
django built-in login demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% 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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)), | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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