直接鏈接到一個視圖:
(r'^accounts/login/', 'myproj.login.views.mylogin')
然後在您的視圖代碼中處理重定向:
def mylogin(request, **kwargs):
if request.user.is_authenticated():
if 'next_url' in request.session:
url = request.session['next_url']
del request.session['next_url'] # Cleaning next_url val
return HttpResponseRedirect('/%s' % url)
else:
return HttpResponseRedirect('/')
return login(request, **kwargs)
@csrf_protect
def login(request, template_name='registration/login.html'):
"""Displays the login form and handles the login action."""
retval = django.contrib.auth.views.login(request, template_name)
clear_session_data(request.session)
return retval
哪一部分Django文檔的你實際閱讀?嘗試閱讀http://docs.djangoproject.com/en/1.2/ref/templates/api/#django.template.Context,然後更新您的問題以更具體。 – 2011-03-08 01:54:14
culov,你正試圖在你的urls.py中做太多。你不應該在那裏指定模板。 – dappawit 2011-03-08 05:24:05