2015-04-23 113 views
0

当我更改密码时,allauth重定向到登录视图。我需要将重定向网址更改为索引页。怎么做?Django-allauth在更改密码时更改重定向url

这是我到目前为止有:

views.py

def change_password(request, *args, **kwargs): 
    return Http404 

urls.py

url('^password/change/$', 'change_password', name='change_password'), 

,但它仍然重定向我到登录页面;/

回答

0

尝试将您的看法更改为:

def change_password(request, *args, **kwargs): 
    return HttpResponseRedirect("/") //put the name of the url you want to change to within the quotes. As it stands, it will take you to, I'm assuming, what your homepage would be. 

确保导入:

from django.shortcuts import render, HttpResponseRedirect 
0

您的应用程序views.py文件中,覆盖的Django PasswordChangeView allauth

from django.core.urlresolvers import reverse_lazy 
from allauth.account.views import PasswordChangeView 


class LoginAfterPasswordChangeView(PasswordChangeView): 
    @property 
    def success_url(self): 
     return reverse_lazy('generic:password_change_success') 


login_after_password_change = login_required(LoginAfterPasswordChangeView.as_view()) 
在urls.py

(Django在何处allauth网址居住)。上述 这个网址建议立即进行删除自带高于此(URL(R '^账户/',包括( 'allauth.urls')))覆盖默认密码更改行为

url(r'^accounts/password/change/$', generic_views.login_after_password_change, name='account_change_password'), 

url(r'^accounts/', include('allauth.urls')), 

此功能succefully变更后重定向密码。 在这里你必须在帐户模板文件夹这个名字 “password_change_success.html” 创建一个HTML页面

@login_required 
def password_change_success(request): 
    template = "account/password_change_success.html" 
    return render(request, template) 

在url.py

url(r'^password_change_success/$', views.password_change_success, name="password_change_success"),