Django HttpResponseRedirect vs render_to_response - how to get a login form to behave the way I need it to

谁都会走 提交于 2019-12-03 21:55:34

Replace the HttpResponse here with a redirect:

if user.is_active:
    login(request, user)            
    state = "You're successfully logged in!"
    return render_to_response('ucproject/portal/index.html', 
           {'state':state, 'username':username}, context_instance=RequestContext(request))

Instead, you want to use a name in urls.py to disambiguate:

urls.py
url(r'^portal/$', 'portal.views.portal', name='home'),
url(r'^portal/index.html$', 'portal.views.portal', name='home_index'),

then use something like this in your view:

if user.is_active:
    login(request, user)
    return redirect('home')

redirect is a shortcut function, but you could also create and return an HttpResponseRedirect object. Usually there's no point in doing that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!