我用另一個函數包裝了django.contrib.auth.views.logout
以添加其他行爲。這是我的新logout_page:在Django中添加代碼以註銷視圖的正確方法
views.py
from django.contrib.auth import logout
def logout_page(request, *args, **kwargs):
from django.utils import timezone
user = request.user
profile = user.get_profile()
profile.last_logout = timezone.now()
profile.save()
logout(request, *args, **kwargs)
和
urls.py
(r'^logout/$', 'main.views.logout_page', {'next_page': '/'})
但我發現了以下錯誤:
logout() got an unexpected keyword argument 'next_page'
我不確定爲什麼是'nex t_page'當註銷包含** kwargs時的一個意外的參數,據我所知,從django.contrib.auth註銷應該包含這樣的參數。從來源:
https://github.com/django/django/blob/master/django/contrib/auth/views.py
def logout(request, next_page=None,
template_name='registration/logged_out.html',
redirect_field_name=REDIRECT_FIELD_NAME,
current_app=None, extra_context=None):
...
我該如何解決這個問題?
哦,你是對的。我沒有收到錯誤。我想我正在使用正確的導入,除了在我看來。謝謝! – 2012-08-05 05:24:30