我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用django.utils.decorators.decorator_from_middleware()。
def test_with_extra_meta(self): req = self.rf.get('/') for f in getattr( MultipleProxyMiddleware, 'FORWARDED_FOR_FIELDS' ): req.META[f] = 'Value1' del(req.META['HTTP_X_FORWARDED_SERVER']) req.META['HTTP_X_FORWARDED_FOR'] += ',Foo' req.META['SERVER_SOFTWARE'] = 'foo/1.1' viawrap = decorator_from_middleware(ViaHeaderMiddleware) mulwrap = decorator_from_middleware(MultipleProxyMiddleware) viawrap(mulwrap(goodview))(req)
def via_header(view_func): return decorator_from_middleware( import_string('headers.middleware.ViaHeaderMiddleware') )(view_func)