Hi guys,
I have some code added to my logout method so that it redirects users
to the page they were last looking at rather than back to the root of
the site. The code is below.
@turbogears.expose()
def logout( self ):
identity.current.logout()
previous_url =
cherrypy.request.headerMap.get("Referer", "/")
original_parameters=cherrypy.request.paramMap
itemlist='?'
for name,value in original_parameters.items():
itemlist=itemlist+'%s=%s&' % name,value
itemlist=itemlist[:-1]
previous_url=previous_url[52:]+itemlist
raise turbogears.redirect(previous_url)
**As a side note, anyone who wants to use this code should change the
52 in brackets to the length of your base url. This is my lame hack to
fix a problem with the entire web address being repeated twice. **
This works just fine in the logout method, but I've tried to copy it
into another section (my "edit" section, where people can edit
descriptions of pictures), and I get an error from identical code. The
only difference between the two methods is that one has an
@identity.require (the edit method), and the other (the logout method)
doesn't. I'm lost as to why this error is popping up from similar
code. Any ideas?
The error:
File
"/home/.castor/mikez0r/lib/lib/python2.4/site-packages/CherryPy-2.2.0beta
-py2.4.egg/cherrypy/_cphttptools.py", line 98, in _run
self.main()
File
"/home/.castor/mikez0r/lib/lib/python2.4/site-packages/CherryPy-2.2.0beta
-py2.4.egg/cherrypy/_cphttptools.py", line 246, in main
body = page_handler(*virtual_path, **self.params)
File
"/home/.castor/mikez0r/lib/lib/python2.4/site-packages/TurboGears-0.9a0de
v_r544-py2.4.egg/turbogears/controllers.py", line 240, in newfunc
html, fragment, *args, **kw)
File
"/home/.castor/mikez0r/lib/lib/python2.4/site-packages/TurboGears-0.9a0de
v_r544-py2.4.egg/turbogears/database.py", line 189, in
run_with_transaction
retval = func(*args, **kw)
File
"/home/.castor/mikez0r/lib/lib/python2.4/site-packages/TurboGears-0.9a0de
v_r544-py2.4.egg/turbogears/controllers.py", line 257, in _execute_func
output = func(self, *args, **kw)
File
"/home/.castor/mikez0r/lib/lib/python2.4/site-packages/TurboGears-0.9a0de
v_r544-py2.4.egg/turbogears/identity/conditions.py", line 230, in
_wrapper
return fn( self, *args, **kwargs )
File
"/home/.castor/mikez0r/elementarycatastrophe.com/photogal/photogal/contro
llers.py", line 416, in edit
itemlist=itemlist+'%s=%s&' % name,value
TypeError: not enough arguments for format string
Thanks,
Mike