<p>下面是一些代码(我已经删减了)<a href="https://github.com/mitsuhiko/flask/blob/master/flask/app.py#L949" rel="nofollow">from the Flask app object</a>。这段代码处理添加一个url规则(这也是flask调用的内容应用程序路径()在您的视野中)。。。。在</p>
<pre><code>@setupmethod
def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
""" I remove a ton the documentation here.... """
if endpoint is None:
endpoint = _endpoint_from_view_func(view_func)
options['endpoint'] = endpoint
methods = options.pop('methods', None)
# if the methods are not given and the view_func object knows its
# methods we can use that instead. If neither exists, we go with
# a tuple of only `GET` as default.
if methods is None:
methods = getattr(view_func, 'methods', None) or ('GET',)
methods = set(methods)
# ... SNIP a bunch more code...
rule = self.url_rule_class(rule, methods=methods, **options)
rule.provide_automatic_options = provide_automatic_options
self.url_map.add(rule)
</code></pre>
<p>正如您所看到的,Flask将尽最大努力确保方法被明确定义。现在,Flask是基于Werkzeug的,而生产线。。。在</p>
^{pr2}$
<p>…通常使用<a href="http://werkzeug.pocoo.org/docs/routing/#werkzeug.routing.Rule" rel="nofollow">Werkzeug's Rule</a>类。这个类有关于“methods”参数的以下文档。。。在</p>
<blockquote>
<p>A sequence of http methods this rule applies to. If not specified, all
methods are allowed.</p>
</blockquote>
<p>所以,这告诉我你也许可以做如下的事情。。。在</p>
<pre><code>from werkzeug.routing import Rule
app = Flask(__name__)
def my_rule_wrapper(rule, **kwargs):
kwargs['methods'] = None
return Rule(rule, **kwargs)
app.url_rule_class = my_rule_wrapper
</code></pre>
<p>我还没有测试过,但希望这能让你走上正轨。在</p>
<p><strong>编辑:</strong></p>
<p>或者你可以用DazWorrall的答案,这似乎更好:p</p>