Adding forgot-password feature to Django admin site

前端 未结 2 1380
闹比i
闹比i 2021-01-31 05:35

How to add the forgot-password feature to Django admin site? With email/security question options? Is there any plug-in/extension available?

2条回答
  •  无人共我
    2021-01-31 06:27

    Actually since Django 1.4 there's an easy way to get the forgotten password link appear directly in the admin login page (which sounds like the precise question asked):

    https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#adding-a-password-reset-feature

    You can add a password-reset feature to the admin site by adding a few lines to your URLconf. Specifically, add these four patterns:

    url(r'^admin/password_reset/$',
        'django.contrib.auth.views.password_reset',
        name='admin_password_reset'), (r'^admin/password_reset/done/$',
        'django.contrib.auth.views.password_reset_done'),
    (r'^reset/(?P[0-9A-Za-z]+)-(?P.+)/$',
        'django.contrib.auth.views.password_reset_confirm'),
    (r'^reset/done/$',
        'django.contrib.auth.views.password_reset_complete'), 
    

    (This assumes you’ve added the admin at admin/ and requires that you put the URLs starting with ^admin/ before the line that includes the admin app itself).

    Changed in Django 1.4 The presence of the admin_password_reset named URL will cause a “forgotten your password?” link to appear on the default admin log-in page under the password box

提交回复
热议问题