【问题标题】:i did all the instruction on the documentation but i still get this error我完成了文档上的所有说明,但我仍然收到此错误
【发布时间】:2018-07-11 15:37:16
【问题描述】:

在服务器上找不到请求的 URL。如果您手动输入网址,请检查您的拼写并重试

from flask import Flask
app = Flask(__name__)
@app.route('/user/<username>')
def show_user_profile(username):

    return 'User %s' % username
@app.route('/post/<int:post_id>')
def show_post(post_id):

    return 'Post %d' % post_id
@app.route('/path/<path:subpath>')
def show_subpath(subpath):

    return 'Subpath %s' % subpath

【问题讨论】:

  • 那么,您请求的 什么 URL?
  • 我不能给你答案,因为这是我在烧瓶文档中找到的,这是我在网络应用程序上的第一天,所以我没有任何线索。

标签: python flask


【解决方案1】:

您没有定义回家路线 (/)。因此,当您启动应用程序并导航到应用程序设置说明中指定的 url 时,将打印上面发布的错误。只需导航到您声明的其他路线之一:

/user/someting
/post/someval
/path/somepath

为避免该消息,请像这样创建路由:

@app.route('/', methods=['GET'])
def home():
  return 'Welcome!'

【讨论】:

  • @Hamza.Engineer 主路由不接受参数。当前发生了什么错误?
  • 我在我的代码中添加了主路由,但我得到的只是世界'欢迎'
  • @Hamza.Engineer 这是预期的。将显示路由返回的任何内容。你期待什么?
猜你喜欢
  • 2022-06-20
  • 2019-07-18
  • 1970-01-01
  • 2017-07-06
  • 2021-05-04
  • 2020-12-25
  • 2020-03-16
  • 2013-03-27
  • 1970-01-01
相关资源
最近更新 更多