- Put 'django.contrib.auth' and 'django.contrib.contenttypes' in your INSTALLED_APPS setting. (The Permission model in django.contrib.auth depends on django.contrib.contenttypes.). These should be the default settings anyway after installing Django.
- Run the command manage.py syncdb.
Add @login_required before each view:
e.g.
@login_required (login_url='/accounts/login/')
def myview(request, event_id):
...
return render(request, ...
This redirects the user to /accounts/login, so add the following to the top level urls.py:
url(r '^accounts/login/$' , 'django.contrib.auth.views.login'),
The default login page template is then at registration/login.html:
e.g.
{% extends "base.html" %}
{% load url from future %}
{% 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 align="center">
<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>
<div style="text-align: center;"><input type="submit" value= "login" /></div>
<div style="text-align: center;"><input type="hidden" name= "next" value="{{ next }}" /></div>
</form>
The following URLs are used for password reset
The following templates are required. These are referred to from the url patterns above, plus one for email.
The following templates are required. These are referred to from the url patterns above, plus one for email.
- registration/password_reset_complete.html
- registration/password_reset_confirm.html
- registration/password_reset_done.html
- registration/password_reset_form.html
- registration/password_reset_email.html
registration/password_reset_complete.html
registration/password_reset_confirm.html
registration/password_reset_done.html
registration/password_reset_form.html
{% extends "template.html" %} {% block title %}Password reset{% endblock %} {% block pagetitle %}Password reset{% endblock %} {% block content %}<p>Forgotten your password? Enter your e-mail address below, and we'll e-mail instructions for setting a new one.</p> <form action="" method="post"> {{ form.email.errors }}<p><label for="id_email">E-mail address:</label> {{ form.email }} <input type="submit" value="Reset my password" /></p></form>{% endblock %}
registration/password_reset_email.html
{% autoescape off %}You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}. Please go to the following page and choose a new password:{% block reset_link %}{{ protocol }}://{{ domain }}{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}{% endblock %} Your username, in case you've forgotten: {{ user.username }} Thanks for using our site! The {{ site_name }} team. {% endautoescape %}
No comments:
Post a Comment