[Grok-dev] How do I do a 301 Permanent Redirect?

Uli Fouquet uli at gnufix.de
Sat Jan 24 20:42:25 EST 2009


Hi there,

Sebastian Ware wrote:
> The self.redirect(url) method on a view allways performs a "303 See  
> Other" redirect, but if I want to send a "301 Permanent Redirect", how  
> do I do this?
> 
> I have tried this
> 
>      self.response.setStatus(301, "Permanent redirect")
>      self.redirect("%s" % self.url(o, 'index'))
> 
> But the setStatus doesn't seem to have any effect.

I assume that redirect sets the status code to 303. How should it
otherwise initiate a redirect? So your status setting has no effect.

You might try this:

  self.response.setStatus(301, 'Moved Permanently')
  self.response.setHeader('Location', self.url(o, 'index'))

Maybe that helps.

Best regards,

-- 
Uli

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20090125/db00a80a/attachment.bin 


More information about the Grok-dev mailing list