[mod_python] Detecting Back Button Usage

Jorey Bump list at joreybump.com
Tue Mar 20 09:03:30 EST 2007

Kenneth Loafman wrote:
> Hi,
> This may not be the list I need, but here goes.  I'm new at this whole 
> user interface thing, by nature a low-level systems guy, so be kind.
> I'm using mod_python under Ubuntu Edgy 64, doing some basic plots of 
> data and allowing users to select a point to center on a region and gen 
> the next plot.  All of that works as long as the user moves forward. The 
> problem comes in the use of the back button.  The browser merely 
> displays the last page rather than rebuilding it, or at least restoring 
> the variables.  This leads to a lot of confusion because the server is 
> on one set of plot values and the browser is now on another.  This seems 
> to be a common problem.  Is there a solution, or should I just warn the 
> user not to use the browser back button?

By default, your application has no way of knowing how the client 
requested the URL (other than the unreliable HTTP_REFERER environment 
variable), so it will need to know how to handle all requests, no matter 
what. You can maintain/simulate some sort of state in a variety of 
(somewhat limited) ways on the server side, and everyone has their own 
favorite approach. In any case, you need to expect the unexpected in the 
application itself.

After securing your application, you can add client-side scripting for 
potentially finer control over the requests sent by the client under 
certain circumstances. Typically, you'll use JavaScript, but there are 
other options, depending on your needs. Be aware that while you can 
require that your users depend on this to get use from your application, 
you can't force an arbitrary client to follow such rules, so you do need 
to be prepared when a visitor arrives without JavaScript enabled (for 

Since you're correct that this isn't a mod_python issue, you're most 
likely to get more useful answers in a JavaScript or DHTML forum. There 
are also a number of JavaScript frameworks springing up, due to the AJAX 
craze, and some of these might have useful libraries, so you don't have 
to reinvent the wheel.

More information about the Mod_python mailing list