开发者

Django decorator, adding method to WSGIRequest

开发者 https://www.devze.com 2023-01-19 02:21 出处:网络
Using a decorator I was trying to add a method to WSGIRequest request, just like is_ajax(). Since I could not find a proper way I just updated request.META with the info needed开发者_如何学Python.

Using a decorator I was trying to add a method to WSGIRequest request, just like is_ajax(). Since I could not find a proper way I just updated request.META with the info needed开发者_如何学Python.

Should I look into adding method at runtime in Python ?


You can try to write custom middleware and add this method to request during request process.

See this for more info how to write middleware:

http://docs.djangoproject.com/en/dev/topics/http/middleware/#writing-your-own-middleware

http://www.djangobook.com/en/beta/chapter16/

0

精彩评论

暂无评论...
验证码 换一张
取 消