Script
Script
"Alright, first up, we need to make sure Flask is installed. Open up your command
prompt or terminal and type in the following command: pip install Flask "
"Here, we’re telling Python’s package manager, pip, to install Flask. Flask is the
library we'll use to set up our web server. Pip is basically the tool that helps us
install different Python modules or libraries whic we mentioned in the previos
video.
Once Flask is installed, you’re all set to start coding!"
"Flask is a lightweight and flexible Python web framework that makes it super easy
to build web applications and APIs. It’s often referred to as a ‘micro-framework’
because it doesn’t come with a lot of built-in tools—this means you only include
what you need, keeping your project simple and fast."
"Flask is popular because it’s beginner-friendly, yet powerful enough for real-
world applications. It handles the basics of web development, like routing (which
determines what happens when users visit different URLs) and rendering HTML
templates. You can build everything from small projects to large-scale applications
with it!"
Alright now lets start writing the actual code. I will explain everything in
detail.
Here, we create an instance of the Flask class and store it in a variable named
app. This app object represents our Flask application and will be used to set up
routes and run the server.
__name__ is a special Python variable that represents the name of the current
module (in this case, our script). Flask uses it to understand where to look for
other files and resources, like templates and static files.
@app.route("/"):
This line is a route decorator, meaning it defines a route, or URL, for our app.
"/" is the URL path for this route. In Flask, "/" represents the root URL, which is
typically the homepage. So when someone visits our website’s root (like
http://127.0.0.1:5000/), Flask will execute the function right below this line.
In general, routes tell Flask, “If a user goes to this specific URL, execute the
following code.”
def home()::
Here, we’re defining a function called home(). This function will run whenever
someone visits the root URL (/). Functions associated with routes are often called
view functions in Flask.
return render_template("index.html"):
"This is the file that users actually see when they visit your site. It sets up the
layout, text, images, and all the other elements on the page. HTML is the core
language for web pages, giving structure to everything you display."
The <!DOCTYPE html> and <html> tags tell the browser that this is an HTML5
document.
The <head> section contains metadata, like the page title, which appears on the
browser tab.
The <body> section is where the main content goes. We have an <h1> header and a
paragraph (<p>), which will be displayed on our page."
"With Flask, you can build more complex projects by adding more routes and HTML
templates. You can even use CSS and JavaScript files to style and add interactivity
to your pages, turning Flask into a powerful tool for web development!"