In this section, we will talk about the basics of developing web applications using Flask and Flask-RESTful.
As we discussed earlier, Flask is simple and straightforward. There are no complex rules or steps for developing web applications in Flask.
Perform the following steps to create your first web application using Flask:
Create a module and name it
FlaskWebApp.py
.Edit
FlaskWebApp.py
and add the following code:from flask import Flask webapp = Flask(__name__) @webapp.route("/") def hello(): return " Hello World!" if __name__ == '__main__': webapp.run(host='0.0.0.0',port=8999,debug=True)
Next, open your console or command prompt and execute
py FlaskWebApp.py
. You will see something like the next screenshot:
And we are done!!!
Your first application is up and running on port 8999
.
Next, you can open your web browser and type http://localhost:8999
in the URL navigation bar. You will see "Hello World!"
...