Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python FormDataRoutingRedirect不带斜杠的URL异常_Python_Url_Flask_Python 2.6 - Fatal编程技术网

Python FormDataRoutingRedirect不带斜杠的URL异常

Python FormDataRoutingRedirect不带斜杠的URL异常,python,url,flask,python-2.6,Python,Url,Flask,Python 2.6,我正在执行一个ajax POST请求,我遇到了以下异常: [Fri Nov 29 20:48:55 2013] [error] [client 192.168.25.100] self.raise_routing_exception(req) [Fri Nov 29 20:48:55 2013] [error] [client 192.168.25.100] File "/usr/lib/python2.6/site-packages/flask/app.py", line 1439

我正在执行一个ajax POST请求,我遇到了以下异常:

[Fri Nov 29 20:48:55 2013] [error] [client 192.168.25.100]     self.raise_routing_exception(req)
[Fri Nov 29 20:48:55 2013] [error] [client 192.168.25.100]   File "/usr/lib/python2.6/site-packages/flask/app.py", line 1439, in raise_routing_exception
[Fri Nov 29 20:48:55 2013] [error] [client 192.168.25.100]     raise FormDataRoutingRedirect(request)
[Fri Nov 29 20:48:55 2013] [error] [client 192.168.25.100] FormDataRoutingRedirect: A request was sent to this URL (http://example.com/myurl) but a redirect was issued automatically by the routing system to "http://example.com/myurl/".  The URL was defined with a trailing slash so Flask will automatically redirect to the URL with the trailing slash if it was accessed without one.  Make sure to directly send your POST-request to this URL since we can't make browsers or HTTP clients redirect with form data reliably or without user interaction.
路线定义如下:

@app.route('/myurl')
def my_func():
我可以在Firebug中看到,发送请求时没有尾部斜杠:

http://example.com/myurl
Content-Type    application/x-www-form-urlencoded; charset=UTF-8
我在另一个模块中有这个:

@app.route('/')
@app.route('/<a>/')
@app.route('/<a>/<b>')
def index(a='', b=''):
@app.route(“/”)
@应用程序路径(“/”)
@应用程序路径(“/”)
def索引(a='',b=''):

最后一个会碍事吗?还是怎样Flask版本是0.10.1

我猜您的
/myurl
路由没有定义为接受
POST
请求,并且您的
/。默认情况下,调用使用尾部斜杠定义的路由而不使用该斜杠会触发重定向到URL的尾部斜杠版本。这当然不适用于
POST
请求,因此您会得到
FormDataRoutingRedirect
异常

我怀疑如果你将你的
POST
请求发送到
/myurl/
,那么你的
/
路由将被很好地调用,尽管这显然不是你想要的

我认为您缺少的是在
/myurl
上接受
POST
请求,您可以按如下方式执行:

@app.route('/myurl', methods = ['GET', 'POST'])
def my_func():

我猜您的/myurl路由没有定义为接受
POST
请求,而您的//路由是。它们都没有被定义为接受
POST
或任何其他方法,但当我将
POST
方法添加到
/myurl
时,它起了作用。啊,好的。因此,重定向表单错误发生在Flask确定与您的请求类型不匹配之前。