VJC Chapter 8 Web applications Part 2 (Flask)
Uploaded by cheesemuffin · 10 December 2025
Preview
Chapter 8 Web applications Part 2 (Flask) Contents 1 What is Flask? 1.1 Installing Flask 1.2 Creating a Simple Flask App 1.3 Accessing the App 1.4 Routing in Flask 2 File Hierarchy of a Flask project 3 Using a HTML Template 4 Dynamic webpage 4.1 Using the GET method 4.2 Using the POST method 4.3 Difference between GET and POST methods Annex 1 – Layout.html Syllabus Learning Outcomes 4.2 Web Applications Understand the concepts and techniques for developing web applications. 4.2.3 Use HTML, CSS (for clients) and Python (for the server) to create a web application that is able to: – accept user input (text and image file uploads) – process the input on the local server – store and retrieve data using an SQL database – display the output (as formatted text/images/table). 4.2.4 Test a web application on a local server. 1
1 What is Flask? Flask is a flexible and powerful web application framework that allows developers to build web applications and APIs using Python quickly and easily. Flask provides tools and libraries for handling HTTP requests and responses, managing routing, and handling errors. It also integrates with a variety of popular Python libraries, making it easy to build complex applications with Flask. 1.1 Installing Flask Before we can start building our web application, we need to install Flask. Flask can be installed using pip, which is a package installer for Python. Open up your terminal or command prompt and type: pip install flask This will install Flask and its dependencies. 1.2 Creating a Simple Flask App Now that we have Flask installed, we can write a simple web application by creating a Python file app.py and add the following code: app.py Browser from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Hello World!' if __name__ == '__main__': app.run() This code imports the Flask module, creates a new Flask app, and defines a route that responds with "Hello, world!" when the root URL is requested. In Python, the special variable __name__ is a built-in variable that represents the name of the current module. When a Python script is executed, its __name__ variable is automatically set to '__main__' if it is the entry point to the program. In the context of a Flask web application, __name__ is used to determine the name of the application package. When creating a Flask app, we typically pass __name__ as an argument to the Flask() co
Content continues in the PDF.
Related notes
- VJC Chapter 21 SQLite with PythonNotes/Practices · 2025
- VJC Chapter 23 Web Applications PrinciplesNotes/Practices · 2025
- VJC Chapter 10 RecursionNotes/Practices · 2025
- VJC Chapter 20 SQLNotes/Practices · 2025
- VJC Chapter 16 Hash TableNotes/Practices · 2025
- VJC Chapter 22 NoSQLNotes/Practices · 2025

