expand werkzeug useragent class

 ̄綄美尐妖づ 提交于 2019-12-13 01:51:19

问题


I want to expand werkzeug UserAgent class with one more browser. How can I do it without modifying the source code of werkzeug library? I'm new in python so I have small idea about mixins, inheritance, modules and so on. I've found in docs:

It’s a good idea to create a custom subclass of the BaseRequest and add missing functionality either via mixins or direct implementation. Here an example for such subclasses:

from werkzeug.wrappers import BaseRequest, ETagRequestMixin
class Request(BaseRequest, ETagRequestMixin):
    pass

At which part of my code should I put this and how to expand standart UserAgent class? Also I'm using werkzeug with Flask. Thanks in advance.


回答1:


Amazing. Once you ask question the answer comes up itself :)

Flask.request_class is the answer:

from werkzeug.wrappers import BaseRequest, ETagRequestMixin

class Request(BaseRequest, ETagRequestMixin): 
    pass

app = Flask(__name__)
app.request_class = Request


来源:https://stackoverflow.com/questions/16707143/expand-werkzeug-useragent-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!