flask-tips(01)去掉url末尾的/

来源:互联网 发布:优爵网络 编辑:程序博客网 时间:2024/05/18 01:16

flask对tailing slash默认的处理是/abc会指定向/abc/,访问/abc都会访问/abc/,有时候前端大大不希望


后端实现:

 @mod.before_request def clear_trailing():     from flask import redirect, request     rp = request.path     print request.query_string     if rp != '/' and rp.endswith('/'):         rp = rp[:-1]         if len(request.query_string) > 0:             rp = rp + '?' + request.query_string         return redirect(rp)

app.url_map.strict_slashes = False


nginx实现:

在虚拟主机配置中添加一个rewrite规则

rewrite ^/(.*)/$ /$1 permanent;

0 0