Last active
March 19, 2018 07:03
-
-
Save m-root/4a360a2893555c5f1dcc2e1cecdc0d24 to your computer and use it in GitHub Desktop.
Django authentication template
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
# python manage.py startapp accounts | |
# cmkdir -p accounts/templates/accounts | |
# ccryptomanager.urls | |
# curl(r'^', include('accounts.urls')), | |
############ accounts/urls.py ############ | |
from django.conf.urls import url | |
from django.urls import reverse_lazy | |
from django.contrib.auth.views import ( | |
LoginView, | |
LogoutView, | |
PasswordResetView, | |
PasswordResetDoneView, | |
PasswordChangeView, | |
PasswordChangeDoneView, | |
PasswordResetConfirmView, | |
PasswordResetCompleteView | |
) | |
urlpatterns = [ | |
url(r'^login/$', LoginView.as_view(template_name='accounts/login.html'), name='login'), | |
url(r'^logout/$', LogoutView.as_view(next_page=reverse_lazy('login')), name='logout'), | |
url(r'^password_change/$', | |
PasswordChangeView.as_view(template_name='accounts/password_change_form.html'), | |
name='password_change'), | |
url(r'^password_change/done/$', | |
PasswordChangeDoneView.as_view(template_name='accounts/password_change_done.html'), | |
name='password_change_done'), | |
url(r'^password_reset/$', | |
PasswordResetView.as_view(template_name='accounts/password_reset_form.html'), | |
name='password_reset'), | |
url(r'^password_reset/done/$', | |
PasswordResetDoneView.as_view(template_name='accounts/password_reset_done.html'), | |
name='password_reset_done'), | |
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', | |
PasswordResetConfirmView.as_view(template_name='accounts/password_reset_confirm.html'), | |
name='password_reset_confirm'), | |
url(r'^reset/done/$', | |
PasswordResetCompleteView.as_view(template_name='accounts/password_reset_complete.html'), | |
name='password_reset_complete'), | |
] | |
########################################################## | |
############ accounts/settings.py ############ | |
INSTALLED_APPS = [ | |
... | |
'accounts', | |
] | |
LOGIN_URL = '/login/' | |
LOGIN_REDIRECT_URL = '/' | |
############ accounts/templates/accounts.html ############ | |
{% extends "base.html" %} | |
{% block content %} | |
<form action="" method="post"> | |
{% csrf_token %} | |
{{ form.as_p }} | |
<input type="submit" value="login" /><br /> | |
<a href="{% url "register" %}">Register an Account</a> | |
<a href="{% url "password_reset" %}">Can't Remember Password</a> | |
</form> | |
{% endblock %} | |
########################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment