擅长:python、mysql、java
<p>您可以直接为此更改url映射,方法是添加一个<a href="http://werkzeug.pocoo.org/docs/routing/#werkzeug.routing.Rule" rel="noreferrer">^{<cd1>}</a>,而不使用任何方法:</p>
<pre><code>from flask import Flask, request
import unittest
from werkzeug.routing import Rule
app = Flask(__name__)
app.url_map.add(Rule('/', endpoint='index'))
@app.endpoint('index')
def index():
return request.method
class TestMethod(unittest.TestCase):
def setUp(self):
self.client = app.test_client()
def test_custom_method(self):
resp = self.client.open('/', method='BACON')
self.assertEqual('BACON', resp.data)
if __name__ == '__main__':
unittest.main()
</code></pre>
<blockquote>
<p><code>methods</code></p>
<p>A sequence of http methods this rule applies to. If not specified, all methods are allowed.</p>
</blockquote>