Reputation: 87
I'm new to flask, I'm trying to do a rest api, but when creating my route it doesn't recognize it for me. I have imported flask and python 3.8.
from products import products
from flask import Flask
@app.route('/greeting')
def greeting():
return 'hi'
if __name__ == '__main__':
app.run(debug=True, port=4000)
Upvotes: 0
Views: 36
Reputation: 3502
You need to create the instance of the Flask class
app = Flask(__name__)
A minimal Flask application looks something like this:
from flask import Flask
app = Flask(__name__)
@app.route('/greeting')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True, port=4000)
Now you could see it running at:
* Running on http://127.0.0.1:4000/
Access the greeting as http://127.0.0.1:4000/greeting
For more info read this
Upvotes: 1