This article is a super quick tutorial where I will show you how to install flask on mac and create a flask hello world web application.
This article is a super quick tutorial where I will show you how to install Flask on mac and create a flask hello world web application. You can install Flask in about five lines of code, only following the instructions below.
Usually, programs will take some inputs, then perform some tasks and returns an output. In case you heard about web applications or web services, you might be wondering what’s different between an application(or program) and a web application. A web service is a program that is available over the internet.
This type of program listen for HTTP or HTTPS requests, which are requests arriving from the internet that follow a specific format. The web service will receive the request and create a response. For instance, the response could be a web page. The server will then send the response back to the client’s web browser over the internet.
You can create your web service using Flask Python. Flask is a web framework, a library that provides you with code that listens for internet requests and responds to those requests. Flask is a lightweight library. That means the framework contains minimal functionality to make the application available over the internet and allow it to communicate using web protocols like HTTP or HTTPS.
Now that you know what flask is, it is time to create our hello world.
Installing Flask through pip is quite simple. All you need to do is running this command:
pip install flask
Please note this same command will also work on windows.
We will create a web application that will listen to internet requests and responds with the message
Hello World. In other words, you will be able to send a request from the browser, and you will get a response, “Hello World.” The best part is only you only need to create one file to do this 🙂
# File name: hello_webapp.py from flask import Flask # include the flask library app = Flask(__name__) @app.route("/") def index(): return "Hello, World!" if __name__ == '__main__': app.run(port=5000, debug=True) # application will start listening for web request on port 5000
That’s all you need to do. If everything went well, you can open your browser and send a web request to your web service by entering the following URL in the address bar, and you should see the “Hello World” message.
To summarise, we have seen how to install flask on mac.
I hope you enjoyed this article, and you are now thinking about your next web application.
If you like the article, please subscribe to get notified when I publish more programming articles and how to improve your programming skills.
Become an ethical hacker that can hack computer systems like black hat hackers and secure them like security experts.
Steady pace book with lots of worked examples. Starting with the basics, and moving to projects, data visualisation, and web applications
Unique lay-out and teaching programming style helping new concepts stick in your memory
Great guide for those who want to improve their skills when writing python code. Easy to understand. Many practical examples
Perfect Boook for anyone who has an alright knowledge of Java and wants to take it to the next level.
Excellent read for anyone who already know how to program and want to learn Best Practices
Perfect book for anyone transitioning into the mid/mid-senior developer level
Great book and probably the best way to practice for interview. Some really good information on how to perform an interview. Code Example in Java