Reputation: 1054
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()
Upvotes: 2
Views: 21104
Reputation: 11
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
.
Upvotes: 1
Reputation: 39
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
;)
Upvotes: 1
Reputation: 1832
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?)
Upvotes: 0
Reputation: 1594
Try specifying the port in app.run()
app.run(debug=True,
host='0.0.0.0',
port=9000,
threaded=True)
Upvotes: 2
Reputation: 1128
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)
Upvotes: 2