1

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()
nlogn
  • 894
  • 4
  • 9
  • 17

4 Answers4

2

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)

mmenschig
  • 1,030
  • 14
  • 22
2

Try specifying the port in app.run()

app.run(debug=True, host='0.0.0.0', port=9000, threaded=True)

jyap
  • 1,244
  • 10
  • 5
2

I too faced the same issue. Sometimes there might installation issues I guess.

In my case I just pip uninstalled flask and reinstalled and it worked fine ;)

To pip uninstall use :

pip uninstall flask

and check whether the servers aren't working, it obviously shouldn't then reinstall by

pip install flask

;)

0

Are you submitting a form with the parameter (email_id) you set? Also, make sure you are submitting the form with Content-Type: application/json - otherwise, request.json will be empty. You can also use request.get_json(force=True), but this is not recommended. (See How to get POSTed json in Flask?)

A. Wilcox
  • 1,582
  • 2
  • 10
  • 18