2

In my django App on the login page i want to have a request password button which functions like, when this button is clicked I get a request from the user per email to provide that user a password for the site.At the template login.html I made this change :

    {% extends "base.html" %}
    {% load url from future %}

    {% block site_contents %}

    {% 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" name="request_password" value="Request Password" />
     <input type="submit" value="login" />
     <input type="hidden" name="next" value="{{ next }}" />
     </form>

     {% endblock %}

Where in views can I write code to capture the event request_password and write my code to email to the amdin about user's request?

Thanks in advance

4

1 回答 1

1

I think this would be easier to do by creating a new form and pointing it to your own view. Or, if you want to have it in one form, you can probably create a view along the lines of:

from django.contrib.auth.views login as original_login
def my_login(request):
    if request.method == 'POST' and 'request_password' in request.POST:
        # process password request somehow
    else:
        return original_login(request)

Modifying Django-supplied view would probably just complicate things for you in the long run.

于 2012-07-18T07:35:47.573 回答