def get_referer(req, replace_ampersands=False):
try:<EOL><INDENT>referer = req.headers_in['<STR_LIT>']<EOL>if replace_ampersands == <NUM_LIT:1>:<EOL><INDENT>return referer.replace('<STR_LIT:&>', '<STR_LIT>')<EOL><DEDENT>return referer<EOL><DEDENT>except KeyError:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>
Return the referring page of a request.
    Referer (wikipedia): Referer is a common misspelling of the word
    "referrer"; so common, in fact, that it made it into the official
    specification of HTTP. When visiting a webpage, the referer or
    referring page is the URL of the previous webpage from which a link was
    followed.
    @param req: request
    @param replace_ampersands: if 1, replace & by &amp; in url
                               (correct HTML cannot contain & characters alone)