Each framework has its strengths and weaknesses, and the best choice depends on your project’s specific needs. Moreover, we’ve discovered that Flask’s capabilities extend beyond simple web applications. It’s equally adept at building RESTful APIs, microservices, and even real-time applications.

Currently your application only displays a simple message without any HTML. Web applications mainly use HTML to display information for the visitor, so you’ll now work on incorporating HTML files in your app, which can be displayed on the web browser. Warning Flask uses a simple web server to serve our application in a development environment, which also means that the Flask debugger is running to make catching errors easier. This development server should not be used in a production deployment. See the Deployment Options page on the Flask documentation for more information, you can also check out this Flask deployment tutorial. Once you create the app instance, you use it to handle incoming web requests and send responses to the user.

Use a Flask Blueprint to Architect Your Applications

To indicate that a template is meant to be included, you can prefix its name with an underscore (_). When you visit your Home page, then you can click the link to the About page. Since there’s no link to the Home page, you’d need to either use the Back button of your browser or enter the URL manually in the address bar. By default, Flask expects your templates to be in a templates/ directory. Therefore, you don’t need to include templates/ in the path of the templates. Just like in home.html, you do something nifty with the title block.

Flask Framework for Python Developers Lessons

This prefix is an indication that the environment env is currently active, which might have another name depending on how you named it during creation. The deployment is not an easy topic to be digested by a beginner, and I prefer to provide a sample 100% configured and hide the real complexity covered by some nice scripts. To explain the deployment options, we need a full article that presents the possible and flask developer recommended architectures. To execute a Python program we need to have the Python interpreter available in the terminal. The first step is to access the official download page, download the installer for our operating system (Mac, Linux, M$ Windows) and execute it. If the installation goes well we should be able to access the interpreter from the terminal window (Powershell for windows, Xterm for Linux …).

Save and close the file. The navigation bar will now have a New Post item that links to the /create route.

Defining datatype along with variable name enforces the user to follow the convention while passing the route name to the server. Both are highly recommended in case you are learning to develop web applications. In this example, when a user accesses a URL like /user/john, the value johndoe is captured and passed as the username argument to the profile() View function. Before you start proceeding with this tutorial, we are assuming that you have hands-on experience on HTML and Python.

The –app flag specifies the location of the application it’ll execute — here, the demo.py file. A host of frameworks and libraries make getting a Python application up and running easier. The Flask framework attracts Python developers by supporting easy prototyping and customizability. Throughout this guide, we’ve explored Flask, a lightweight yet powerful web framework in Python. We’ve journeyed from understanding its basics to utilizing its advanced features, and even delved into troubleshooting common issues.