def redirect_or_next(endpoint, **kwargs):
 return redirect((request.args.get('next') or endpoint), **kwargs)

def redirect_or_next ( endpoint , ** kwargs ) : return redirect ( ( request . args . get ( 'next' ) or endpoint ) , ** kwargs )
redirects the user back to the page they were viewing or to a specified endpoint .