• flask中错误使用flask.redirect('/path')导致的框架奇怪错误


    我在首页的位置使用了如下代码:

    import flask
    @page_index.route('/')
    def index():
        flask.redirect('/pythoncgi/')
    

    结果站点出现以下错误:

    [11/Nov/2019 15:03:01] "GET / HTTP/1.1" 500 -
    Traceback (most recent call last):
      File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 2463, in __call__
        return self.wsgi_app(environ, start_response)
      File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 2449, in wsgi_app
        response = self.handle_exception(e)
      File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 1866, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "/usr/local/lib64/python3.6/site-packages/flask/_compat.py", line 39, in reraise
        raise value
      File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
        response = self.full_dispatch_request()
      File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
        return self.finalize_request(rv)
      File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 1967, in finalize_request
        response = self.make_response(rv)
      File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 2097, in make_response
        "The view function did not return a valid response. The"
    TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
    

    解决方法如下:

    @page_index.route('/')
    def index():
        return flask.redirect('/pythoncgi/')
    
  • 相关阅读:
    替换configparser 中指定的值
    configparser 读取与赋值
    接口测试第五步 --》 拼接url
    接口测试第四步 --》 封装excel
    接口测试第三步 --》 封装请求方法
    接口测试第二步 --》 推荐定义一个log 文件
    超级直观理解tcp握手
    crash 潜水
    提高MySQL查询速度
    JSON文件存入MySQL数据库
  • 原文地址:https://www.cnblogs.com/ahfuzhang/p/11835454.html
Copyright © 2020-2023  润新知