Search code examples
pythonpython-3.xflask-restful

Python Flask App route not working as expected


I am not able to get the http://127.0.0.1:5000/user1 Url from the browser every time it gives 404 and for the http://127.0.0.1:5000 it gives old output which I have tried (some other string "Hello flask") instead of "hello world" I have tried closing my IDE and trying again even I have created another project but the problem still persist

Thanks in advance!

#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()

Solution

  • Are you restarting the server when reloading @app.route('/')? Also, try clearing your cache. With Chrome, you can do that by hitting SHIFT + F5.

    @app.route('/user1', methods=['POST']) moves to abort since you are not posting anything in your view. What exactly are you trying to do in this route?

    Also, while developing, I recommend running app run with the debug parameter:

    app.run(debug=True)