一种更简单的方法依赖于页面LOGIN_REDIRECT_URL的重定向。要实现的关键是将用户信息自动包含在请求中。
假设:
LOGIN_REDIRECT_URL = '/profiles/home'
并且你已经配置了urlpattern:
(r'^profiles/home', home),
然后,你只需要为视图编写
home():
from django.http import HttpResponseRedirectfrom django.core.urlresolvers import reversefrom django.contrib.auth.decorators import login_required@login_requireddef home(request): return HttpResponseRedirect( reverse(NAME_OF_PROFILE_VIEW, args=[request.user.username]))
NAME_OF_PROFILE_VIEW你正在使用的回调的名称在哪里。使用django-profiles,
NAME_OF_PROFILE_VIEW可以是’profiles_profile_detail’。



