每次它给出 404 时,我都无法从浏览器中获取 http://127.0.0.1:5000/user1 Url,而对于 http://127.0.0.1:5000 ,它给出了我尝试过的旧输出(其他一些string “Hello flask”) 而不是 “hello world” 我已经尝试关闭我的 IDE 并再次尝试,即使我已经创建了另一个项目,但问题仍然存在
提前致谢!
#imports
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'hello world!'
#add users to collection "app_users"
@app.route('/user1',methods=['POST'])
def add_user():
if not request.json or not 'email_id' in request.json:
abort(404)
print("processing")
insert(request)
return flask.jsonify({'status': "inserted successfully"}), 201
if __name__ == '__main__':
app.run()
原文由 nlogn 发布,翻译遵循 CC BY-SA 4.0 许可协议
重新加载时是否重新启动服务器
@app.route('/')
?另外,尝试清除缓存。使用 Chrome,您可以通过按 SHIFT + F5 来完成此操作。@app.route('/user1', methods=['POST'])
移动到中止,因为您没有在您的视图中发布任何内容。你到底想在这条路线上做什么?此外,在开发时,我建议使用调试参数运行应用程序:
app.run(debug=True)