2015-04-23 92 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"),