C小白巴巴巴 2023-11-22 19:36 采纳率: 0%
浏览 4

flask 404错误

img

img

img


flask数据库通过表单添加数据时出现Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.这个问题怎么解决啊

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-11-23 04:42
    关注

    【相关推荐】



    • 这个问题的回答你可以参考下: https://ask.csdn.net/questions/190182
    • 这篇博客你也可以参考下:使用flask模块,登录http://127.0.0.1:5000/,浏览器报错The requested URL was not found on the server. If you entere
    • 您还可以看一下 李焱兵老师的python flask web开发入门与项目实战课程中的 flask的url的反转小节, 巩固相关知识点
    • 除此之外, 这篇博客: Flask 路由404 Not Found中的 新的改变 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
      from flask import Flask
      app = Flask(__name__)
      @app.route('/')
      @app.route('/say')
      @app.route('/hello')  #只有这一个错误
      @app.route('/hellozm')
      @app.route('/say_h')
      @app.route('/say_hello')
      def index():
         return 'hello world'
      app.run(debug=True)
      

      当运行的时候,其他路由都能正常显示,就第三个 /hello 报错404 not found。The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
      也就是请求不到资源。
      不科学呀,其他的都行,凭啥/hello不行,检查发现,当你在浏览器输入http://127.0.0.1:5000/hello 回车后,变成了http://127.0.0.1:5000/hello/ ,后面多了一个斜杠。 这就能解释为啥请求不到资源了。

      至于为啥我输入/hello,结果却变成了/hello/,有没有小伙伴知道的可以评论下,我猜测大概是浏览器的问题。

      为了避免这种问题,可以统一在URL地址输入 /hello/ 类似的格式。这样后面的斜杠没有输入,也不会报错。


    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 11月22日