展开werkzeug useragent类 [英] expand werkzeug useragent class
问题描述
我在文档中发现:
lockquote
创建BaseRequest的自定义子类并添加缺少的功能是个好主意通过mixin或直接执行。这里是这样一个子类的例子:
from werkzeug.wrappers import BaseRequest,ETagRequestMixin
class Request(BaseRequest,ETagRequestMixin):
pass
我把这个和如何扩展标准的UserAgent类?另外我用烧瓶与werkzeug。提前致谢。
惊人的。一旦你提出问题,答案就会出现:)
from werkzeug.wrappers import BaseRequest,ETagRequestMixin
$ b $ class Request(BaseRequest,ETagRequestMixin):
pass
$ b $ app = Flask(__ name__)
app.request_class =请求
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.
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
这篇关于展开werkzeug useragent类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!