【发布时间】:2017-10-31 14:35:42
【问题描述】:
我正在构建一个自定义 Prometheus 中间件类来进行一些监视,我想为中间件中的给定请求构建或检索 Django Rest Framework Request 对象,以便我可以在我的指标。
但是,我下面代码中的request 参数似乎是WSGIRequest 对象。是否可以在中间件中识别 DRF HttpRequest 对象?下面的代码...
if django.VERSION >= (1, 10, 0):
from django.utils.deprecation import MiddlewareMixin
else:
MiddlewareMixin = object
class CustomPrometheusAfterMiddleware(MiddlewareMixin):
def process_response(self, request, response):
# Do some cool things
return response
【问题讨论】:
-
@Alasdair 我首先要发表相同的评论,但 OP 想要的是 DRF 的
Request对象。 -
中间件类的顺序是什么?可以发一下吗?
标签: python django django-rest-framework prometheus