fluent_contents.middleware¶
The HttpRedirectRequestMiddleware class¶
-
class
fluent_contents.middleware.HttpRedirectRequestMiddleware(get_response=None)¶ New in version 1.0.
Middleware that handles requests redirects, requested by plugins using
ContentPlugin.redirect(). This needs to be added toMIDDLEWARE_CLASSESfor redirects to work.Some background:
Since plugins can’t return a
HttpResponseRedirectresponse themselves, because they are part of the template rendering process. Instead, Python exception handling is used to abort the rendering and return the redirect.When
ContentPlugin.redirect()is called, aHttpRedirectRequestexception is raised. This middleware handles the exception, and returns the proper redirect response.-
process_exception(request, exception)¶ Return a redirect response for the
HttpRedirectRequest
-
process_template_response(request, response)¶ Patch a
TemplateResponseobject to handle theHttpRedirectRequestexception too.
-