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
  • 1,034
  • 4
  • 11
  • 17

5 Answers5

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,088
  • 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,494
  • 1
  • 11
  • 5
1

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,782
  • 2
  • 12
  • 18
0

I know this question is old and what I say may not answer this question in particular, but my problem was that I was forgetting to add the @ before the app.route. The correct way is: @app.route.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 11 '23 at 23:09