I want to set a plone website to redirect to came_from parameter in url after user logout. For login I set string:${globals_view/navigationRootUrl}/login?came_from=${context/absolute_url}
and it is working.
我想设置一个plone网站,在用户注销后重定向到url中的came_from参数。对于登录我设置字符串:$ {globals_view / navigationRootUrl} / login?came_from = $ {context / absolute_url}并且它正在工作。
For logout this is not working. I tried also with its event:
对于注销,这不起作用。我也试过它的事件:
<subscriber
for="Products.PlonePAS.events.UserLoggedOutEvent"
handler="blabla.goCameFromAfterLogout"
/>
using:
def goCameFromAfterLogout(event):
""" Redirects user to came_from url parameter after logout
"""
import pdb; pdb.set_trace( )
request = event.object.REQUEST
came_from = request.form.get('came_from', None)
if came_from:
response = request.RESPONSE
response.redirect(came_from)
The event is ok, the came_from parameter is ok, but the code is not working how I want. The website redirects me to /logged_out
every time.
事件没问题,came_from参数没问题,但代码不能正常工作。该网站每次都会将我重定向到/ logged_out。
So, how can I set this?
那么,我该怎么设置呢?
3 个解决方案
#1
A simple way: customize logged_out
, transform it to a Python Script that redirect to whatever page you want:
一种简单的方法:自定义logged_out,将其转换为Python脚本,重定向到您想要的任何页面:
context.REQUEST.RESPONSE.redirect(url)
#2
You can also raise a Redirect exception in your event handler
您还可以在事件处理程序中引发重定向异常
from zExceptions import Redirect
def goCameFromAfterLogout(event):
""" Redirects user to came_from url parameter after logout
"""
request = event.object.REQUEST
came_from = request.form.get('came_from', None)
if came_from:
raise Redirect(came_from)
#3
Also ?next=url
instead of came_from is a good idea.
还有?next = url而不是came_from是一个好主意。
#1
A simple way: customize logged_out
, transform it to a Python Script that redirect to whatever page you want:
一种简单的方法:自定义logged_out,将其转换为Python脚本,重定向到您想要的任何页面:
context.REQUEST.RESPONSE.redirect(url)
#2
You can also raise a Redirect exception in your event handler
您还可以在事件处理程序中引发重定向异常
from zExceptions import Redirect
def goCameFromAfterLogout(event):
""" Redirects user to came_from url parameter after logout
"""
request = event.object.REQUEST
came_from = request.form.get('came_from', None)
if came_from:
raise Redirect(came_from)
#3
Also ?next=url
instead of came_from is a good idea.
还有?next = url而不是came_from是一个好主意。