 Hey guys, John Hammond here. So in this video, I want to showcase Python Flask. So Flask for Python is a micro framework for creating websites and web applications all within Python. And it's awesome. It's super clean. It's super cool. It's pretty prevalent in the capture-to-flag scene. I see a lot in different challenges. Personally, I've used it to develop some like web-oriented challenges. And it's awesome for like rapid prototyping and quick development of an application that you want because you've got that web interface front-end like HTML, CSS, JavaScript, and jQuery for those pretty animations. And you've got Python in the background as your back-end programming language. And you have all the power that you would normally have with Python scripting and Python code. So it's awesome. I want to showcase some of the cool things we can do with it in this video series. I am going to be checking out a little bit of the documentation. It's available online at flask.poco.org, flask.poco, I don't know. And I'm going to be using the tutorial as kind of a skeleton or like a jumping-off point for this tutorial video series. And I will be showing the documentation because I want you as viewers to be able to see it, be able to read it and understand it. Kind of have a little bit more exposure to it so you're able to do it on your own later on. So let's get to it. I'm going to open up a terminal, start to work here. As you can see in the easy-to-setup notion here, they do explain that you can install the flask module by using PIP. So PIP is Python's package manager. If you don't have PIP, you can probably pseudo-app install Python PIP. I'm using apps because I'm on Ubuntu, but you'll use whatever is appropriate for your distribution of Linux. And then we can just go ahead and install it with PIP. So pseudo-pip install flask. You may need to use PIP 3 depending on what you're trying to do with Python 2 or Python 3. I'm trying to use Python 3 a little bit more because I know some people had mentioned that I should be using it in the comments and you're totally right. If you need to hit yes to go ahead and approve and agree to it being installed, you can do that. Mine is already installed so there's no need for me to run through that anyway. So I'm going to create a directory that I can work in here. You can do the same if you'd like. And let's get started on a script to start our flask application. So I am trying to use Python 3 and I am trying to keep in touch with the PEP 8 standard. So I have that sublime flake, I think it is, it's called. Installed and that plugin that I'll be using for sublime to keep track of my Python code. But we'll see how it goes. I may have to wrestle with that and I hope that's not too annoying. So normally you wouldn't want to import flask like any other application or any other module that you're trying to import into your own program with the namespace noted here. But flask actually takes advantage of this mentality in this programming mindset of using the WSGI or web server gateway interface. And the way that it does that is through its own application class or an object that you'll typically see. And you can get access to that from that module. So from the lowercase flask import capital flask. And this is the class defining the object or the WSGI object that we'll use in that pretty much house everything for our own application. And you'll see that denoted by this object or variable app that you'll see in a lot of other flask code and we'll just use it to kind of move with the standard. And that will be an instance of this flask class. So whenever you create this object, it needs to be configured and you can like use a flask configuration in a couple of different ways. If you wanted to explore the documentation and tutorials to see the other options, you can do it with a configuration file like external text file to use. You can do it with environment variables or you can do it with just variables local to this script itself. So to do that you use the underscore underscore name variable and then it's everything in the namespace of this script to be treated as the configuration for our app. So once that's created, we want to define routes or locations that we typically be able to go to from the website and access them through our web browser. So the front facing forward slash is kind of the most common one. That's like the root of our web page, right? The index that we go to. Like if you went to johnhamman.org, no page specified, it would bring you to the forward slash to note that that's the top of the website. But you could go to other like router URL locations like view like source or view posts or log in and stuff like that. But let's define one with a Python decorator. So a Python decorator allows us to have some code that essentially goes before and after a regular function. And they're awesome because that's how flask denotes. This is how I'm going to make this function that follows a magic special function that flask can use to really display this out in a web browser. It makes everything super easy and super clean. The way we do it is with an at symbol just the very front and the object that we're working with in this case our application with the route method here. And the argument that will pass in will be the location that we want like forward slash log in or forward slash view posts, etc. Or just the forward slash. So that will be defined as a decorator before our function and that function name can be whatever you want. So if you wanted that to be your login function or your like photos page, etc. I'm just going to call this index because that is our index page. So this is our front page for our flask app. And we'll return just a simple string here, hello world. And that return statement is going to display that out to the web browser. That's essentially what the web browser will get from this location. So when that's returned, we're okay. Now we'll want to run our application. And we can do that with just the typical Python boilerplate if name is equal to main for a typical include guards. And we can run app dot run. Cool. So I'm going to save this and we need a new line at the very end of the file. Thanks to our pep8 standard. Okay, so we're good. Now I'll hop back over to my command line here. We've got that file. We can mark it executable if we'd like. We can run it just like that as a script. And we'll get some notifications that, okay, serving up this flask app, hello world. It's treating it as a production environment. But we'll have to change this to development or debug later on because we're not in a production environment. That'll give us a little bit more testing, a little bit more options. Debug mode is currently off. We can turn on soon, but we'll see where it's running a link in our web browser. Another way of actually starting this is just, you know, Python, hello world. And that doesn't give us that fancy output. But if we wanted to use an even other way to do this by using a flask variable or environment variable, you can say flask app is going to be the name of the script that you want to run. And then the command flask run, that works just fine. So once you install flask, it actually does create a command line program for you that gives you options like run, shell, et cetera, and other things you can do. But they didn't know, okay, if you can use an environment variable to actually go ahead and use that. If I wanted to also explain flask environment equals development, I wonder if that will turn debug on for us. Nope. Okay. I don't know if I can do two variables at once, whatever. So anyway, let's start this server up just like we are doing. And then we can access it in 127.001 at port 5000. So that is the port that flask decides to run on just on localhost because we're doing local development and testing right now. And we get our hello world string. So that's it. Super simple, right? Like not a whole lot of code here, but define a location for application to go to and flask will just serve it up. Super cool, super simple. But we have a lot of power with this. And I want to go into the more in a coming video, like how we can use dynamic URL routing, like how we can actually integrate with a database, like create a login page, a handle post requests, et cetera. Go ahead and work with sessions, work with cookies, do a file upload, a lot of really, really cool stuff. And if you want to dive into the documentation, you can certainly do that too. But I'll try and showcase them in this video series. So hey, thank you guys for watching. I want to give a shout out for my supporters, people that love me on Patreon. I cannot say thank you enough. That's why I do this at the end of every video. All of your support, no matter how big or how small, really does inspire me and motivate me to keep making more cool stuff. If you did like this video, please do press that like button. Maybe comment, maybe subscribe. If you really want to support me, check me out on Patreon. Thanks guys. See you in the next video.