transcribe

Python Flask Tutorial For Beginners | Flask Web Development | Python Training | Edureka Live

edureka! · 26m · transcribed Jul 2026
More from edureka! Business
𝕏 Share ▶ YouTube 📥 PDF 🤖 .md

Section Insights

# 0:00

Introduction to Flask and Python

What is Flask and what are its prerequisites?

Flask is a web application development framework written in Python. It is essential to have a basic understanding of Python, which is an object-oriented, high-level programming language. Python supports various programming paradigms, including procedural and object-oriented styles.

  • Flask is a web framework that simplifies web application development.
  • Basic knowledge of Python is necessary to work with Flask.
  • Python is considered a high-level language, making it easier to write and understand.
# 5:22

Understanding Flask's Functionality

What are the advantages of using Flask for web development?

Flask provides a simple setup for web application development, allowing developers to focus on building applications without worrying about extensive configurations. It uses the Jinja template engine to render HTML, facilitating the separation of UI, controller, and backend functionalities.

  • Flask simplifies the web development process with minimal setup.
  • It uses Jinja for templating, enhancing the rendering of HTML.
  • Flask supports a three-tier architecture: UI, controller, and backend.
# 10:44

Configuring Flask Applications

How can you configure Flask applications, including debugging and routing?

Flask applications can be configured to run on different hosts and ports. The debug mode is useful during development as it displays errors clearly, but it should be turned off in production to prevent exposing code to users. Routing in Flask allows for the handling of different URL patterns and data types.

  • Flask allows configuration of host and port settings.
  • Debug mode is essential for development but should be disabled in production.
  • Routing enables handling various data types in URLs.
# 16:06

Data Handling in Flask Routing

How does Flask handle different data types in URL routing?

Flask can retrieve different data types from URLs, such as integers, floats, and strings. This flexibility allows developers to create dynamic routes that can process various types of input.

  • Flask supports dynamic routing based on different data types.
  • Developers can create routes that accept integers, floats, and strings.
  • Understanding URL routing is crucial for effective web application development.
# 21:28

Using Templates in Flask

Why are templates important in Flask, and how do they work?

Templates in Flask, specifically using the Jinja template engine, allow for dynamic content rendering. Instead of hardcoding HTML for each user, templates enable the substitution of variable values, making it scalable and efficient for applications with multiple users.

  • Templates allow for dynamic rendering of HTML content in Flask.
  • Using Jinja, developers can substitute variables in templates for scalability.
  • Templates help manage content efficiently for applications with many users.

Transcript

0:13 hi everyone a very good evening this is Krishna here I have close to 15 years of experience in it and I've worked in multiple domains right from the software development automation cloud computing machine learning data science fortunately I get a chance to work on multiple things apart from that I have close to 10 plus years of experience in teaching okay so coming to our discussion so we are going to learn about what is a flask how do you install it what is a flask

0:40 application how do you route the flask by using some routing URLs and what are the different templates available in flask then we will see it flask extensions then we will look at a hand saw now coming to python since we are talking about python flask it's very important that you have some knowledge on what python is so python is basically object oriented procedure oriented high level and easy to learn so let's understand what does it mean by high level so high level

1:05 means any language where you can write a program in English is called high level programming language okay just that you are writing that program in English that's what I mean by high level there is another opposite side of it which is called low level language or opposite term of it that means you write the code in terms of the language machine can understand okay that is low level now coming to procedure oriented object oriented those are two paradigms or

1:28 programming Styles available in Python that means you might have heard a lot of terms right structure programming declarative programming functional programming imperative programming meta programming these are all different programming Styles like that python majorly supports two Styles in fact it supports two more Styles also to a very basic extent one is called meta and another is called functional but the majorly what it supports is object oriented and first year oriented so project oriented programming if you want

1:54 to understand at a high level the theme there is whenever you're given a problem you divide the problem into set of functions and start working on it that's what called as first general oriented at a very high level when it comes to object oriented what you do is you actually understand the data first and based on the data you tie up the functions first and create some set of objects and those objects again communicate together in order to build

2:14 the entire project that's where it is called object oriented programming and mainly object oriented programming is used in scenarios where the project is quite complex okay that's where people use it like websites like Amazon Java on the back end they use object under programming languages like Java and all that now coming to easy to Learn Python is very easy to learn the reason being the syntax if you see as well as the notations you see most of them either

2:38 they are reused or so much simplified than other programming languages when they say easy to learn it is easy to learn compared to the existing programming languages we have that's the best part of python and it is integrated by a mathematical scientist and applied mathematician called ketogenism and is like his summer project some vacation project he has built and that's where it started python does not mean any snake and all it's just a comedy circus name

3:01 he used to watch in BBC which the program episode name is Monty Python circus So based on that he picked the name now coming to flask what exactly is flask flask is basically a web application development framework so first of all it's very important that you should understand web application development framework nobody asking an Indian interview who we created flask who created Jango or not nobody are really interested to know about the scientist name so even if you forget

3:27 this guy's face or name it's still okay what you need to understand is what exactly mean by web application development framework so just to give you an idea think like if you want to host a website just a small website where it will show some kind of products you are listing whatever you have built let's say you have built a small Amazon kind of site where you have 10 15 products in it and just you are showing and selling to

3:50 people just this one you want what exactly things you want you want a server to host that particular program because it's nothing but a program when I say website is nothing but a program in order that website to run you need a server where it can run apart from server whenever you make a request to that particular project which is running on your server server is nothing but host when it runs on it obviously the request has to be taken out from there

4:16 the request has to be processed and there the backend has to be connected all that has to happen these all things combining if at all earlier these were not there if at all these all things are provided to you as a whole application and you just need to put in places where you have to do this you have to do this that kind of thing not just setting up all the these things whatever I spoke about that's called Web application

4:38 development framework that means you have some pre-built modules already available where using which you can easily do that before that everything you need to set up okay so that's not mean by web application development framework whether you use flask whether you use Django both are web application development framework flask is a Mini web application for the minimum small application this guy works well but if you are thinking about applications to build at a very high scale jungle works

5:02 really well and the other highlights are flask because that is our topic of discussion it's an open source that means the code is freely available on the internet you can go and check how they have written it another thing is it has a large community when I say community it has lot of users who developed it there you can post a question and get a cancer or if there's a bug they can help you in clarifying

5:22 and all that this is about web application development framework which I just spoke about there is a web developer and he is writing application and in order to do that lot of things need to be done like everything you need to set up that's what I said but using plastic is pretty easy or using Django also any of the web application development framework the advantages most of the setup you need is available you just need to use the right modules

5:42 in order to get the work done so these guys exist in order to make your website kind of developments faster okay that's why web application development Frameworks are very popular so what exactly flask will do flask is basically written in Python and it's actually provides you this wgs toolkit and it uses Ginger to template ninja so what exactly template engines are like when you write HTML if you look at any website development basically it is a

6:10 three direct architecture three direct nature how I'm saying is there will be a UI there will be a controller and there will be a backend that means when I say UI the HTML page opens to the user if you take Amazon amazon.in that UI is your presentation layer that means something which is visible to users once they click on it the request will go to the server Amazon server that is your controller and that server process and

6:34 get some information from the database that is your backend database kind of thing so if you see there are three high level layers involved so in this in order to render the data rather than using plain HTML people use something called templates Django has by default dtl which is called Django template the language just it also supports Jinja just like that flask also supports Ginger it is just to ensure that the different variable names if you want to do it you can make it

7:01 easily using this template and all and it's a small language which you can easily learn now how to install flask it is just a python command you can just say pip install flask that's one easy way but before installing flask or Django if at all you are not using virtual environment this all has to be run in Virtual environment you need to install that first but if you are using an editor like Pi charm I use editor like pysham and in

7:30 pythm if you see everything is by default created in a VNV which is virtual environment so there you do not have headache you can directly work on it you do not need to execute those commands to create it so I would suggest if at all you are interested in working on flask or Django the best part is pychomp and that is very useful you don't need to do all this hard work of creating the project virtual environment

7:51 these all headache will not be there so once you want to install flask this is how you will install and flask Bill gets installed automatically and the flask application looks something like this so understand the skeleton first which is very important what this application basically does is whenever you run this program so what this program says is whenever you run it automatically once it starts running it will open the Local Host which is IP called

8:23 127.0.0.1 and the default Port flask uses is 5000 it will open into that and what would happen is as soon as the page opened by default it is having slash at the end so it says whenever somebody opens that page you just call this function that's what it means so it says that whenever somebody opens a URL with a slash at the end just call this function that's what it means so I can show you quickly so let's say the same

8:49 program I have written let's close this guys for some time let's open the actual program the same program so if you see I'm running here so it started running so you see it is starting and you see where it opened 13700.1 scores in five thousand you can change the port also while you are running but this is the default one once you open you see hello world how are you because by default there will be a forward slash comes even you don't

9:18 specify so that forward slash when it comes hello world how are you how it is coming is because I said whenever somebody opens the page call this function and what this function has hello world how are you that is how it gets triggered and every time you get a response on what is happening and all that so you can see that in just a second of time I am able to open a web server this is what opening a web server

9:40 in my local system and I am able to call a function very simple right that's the best part of these development Frameworks you don't need to do a lot of hard work okay that's the first program now here there are certain things when I run it how it happens is you can see that whenever I run this gets called and automatically this particular program will be listening for your request and as soon as that slash comes which is by

10:03 default for every URL it triggers it calls this function so in flask what happens is there is a binding between the route you have put with the functions that is how entire things works it is always based on the route that means you are seeing on the URL somebody gives this particular thing you automatically call this function that's what you are saying this route like I just called out you can see that here we mentioned the route

10:26 that route is what we are talking about you can give a rule that means you rule is here in the earlier case I have just put slash you can even say slash hello when you give I want to call this all that you can do and there are additional options also you can pass a part from this and this run when you are doing if you see we are already doing this run like I said you can change the port and all

10:48 this I am doing right by default it opens 1370.0.1 let's say you want to change the host name or you want to change the port name that is still possible what you need to do simply is while you are calling that app.run you see there is a host Port options you just have to mention it in the earlier case I didn't mention that's why it is opening to 1370.01 and port 5000. in case you give a different hostname it can open to that

11:11 but localhost I don't have any server unless I actually have a server I can put a server name otherwise it's not useful you can see I already set to debug equal to true I use that attribute and these are all optional if you want you can use it or you can leave it as it is debug mode as you see that's what I have done the advantage with having the debug mode is If You observe Whenever there is

11:32 an array error in the program it is clearly visible here in my program there is no error but if there is an error you can see here in the website also it will display debug mode is generally turned on while you are doing development but once the code goes into production people will not put the debug mode as true because if you're making debug mode as true that means any problem comes customer can see your code which is not

11:51 a good idea right what if he is a hacker he can active a website based on understanding your code so there you will turn on this debug equal to false but generally while doing development that means during you are developing that particular product you will make debugging World true so that you can easily navigate now coming to routing routing is nothing but how you route the URL like in that in our case we have put slash similarly

12:13 you can put any name that means whenever somebody put on the URL the default 127.0.0.1 colon 5000 slash hello they gave this triggers this function that's what it means let me see I think I have that program you see the same one I can put like the slash hello now what I'm saying is whenever somebody puts hello just call this function that's what I'm saying now you see this if I refresh it's not coming because I change the url

12:44 route it's not just slash it is slash hello so now if I put slash hello here now that hello thing comes you see Hello thing it is now me coming slash hello because I change the route it is all depends on what is the route you're putting so it is like URL to function mapping it's just like that that is called the routing part of it I'm just covering the demo also because covering at the end and looking at in

13:11 the PPT you will not able to relate believe me it is all like Theory you will find it so I'm just based on whatever the concept is I'm showing you the demo so you can easily correlate now you see this is one way of doing it this is using decorator there is at the rate there is other way also which is using add URL rule using that also you can bind a URL with a function so here it is so you in that case you

13:35 don't need to put that that is other way of doing it is using this app dot add URL rule where you're saying whenever somebody put slash hello call this function hello world that's what you're saying this is another way of binding your url to a function now in the flask there are certain variable rules what does it mean by variable rule is let's say after hello you have given a name and you want to say hello Krishna

13:56 something but the name is coming from the URL so that name you should be able to retrieve so to quickly show you so I'll show you program you can see that here I am putting any it's a variable so this less than greater than I have put right this is a variable and that's the name I am receiving here the same thing so what does it mean is somebody puts after hello anything it will be stored in name variable and it will be

14:20 passed to this function and that is what I am displaying so you see that here if I stop this guy and I'll run this guy you will understand what I mean I just ran this guy now it is running for this particular program now if I opened it by default I open it it will come hello world because this slash if I give this function will get triggered but after if I put a slash hello slash anything

14:45 like for example let me put slash hello slash Allen so it will say hi hello Helen how are you see hello so how it knows this is the URL in the URL the name is given is like I said this is your variable between less than greater than you have put this one is captured in this variable name name and that is what we are receiving and that's what we are using in here saying hello alert you can put anything maybe you can

15:11 use this name to process and all that there's a lot of things you can do but the gist of it you have to understand is this is your variable this is the same thing hello slash that is receiving and all that and not only that if at all you want to read integer or only float that is also possible okay like here for the blog they are reading it as an integer not name they want to create as integer but

15:33 here they want to be eating as a float that is also you can do it that's also quite possible like let me show that integer part thing I'm just stopping this in demo 3 I'm doing the same I am going to run this guy now if you see here this URL root says after whatever URL opens like if you just open slash it will be hello world only Hello World it will come but after that if I put a route like slash blog

16:03 slash sum integer so it says this particular variable is posted is what the function is C but it must be an integer so if I put slash blog slash 100 000 you see block number is thousand so that is getting retrieved similarly if I want to pass a float number I can have another URL wrote saying float colon so that is for Rev you see division number is one or two point two two three so what I'm trying

16:34 to demonstrate is you can receive different data type elements this is integer this is float this is string string we already have seen this is by default string only so that's how you can receive different different variables and you can work on it similarly one thing to understand here is generally when you say slash python equal to slash python is what we are understanding is just not correct this URL root and this URL root is different

16:56 that's one thing you need to understand so since this particular thing if you look at the web application development framework which we are discussing about is mostly related to Python and let's say if you want to get a good hold of python we have a course separated separately for it this is our course where we will discuss about all the python Basics starting from the bare minimum Basics and make you Masters in Python and the first format you say

17:21 related to Python and also we will give a good coverage on data science topics as well this is that particular course but let's say you are interested only on the web application development framework we have another course called python certification training using Django that also have the same coverage but that will have a purely on the Django thing that means only on the web application development framework that's the only difference but the first four modules which are seeing here there also

17:43 you will see the same now flask URL binding till now what we are doing is the same if you want you can dynamically do it also still now what we are doing is this is static that means before it's compiling it already knows about it but let's say during runtime it has to decide that means while the program is running that time if you want to do this redirect really work using redirect you can do that this

18:05 redirect and all using that you can automatically change it based on a particular attribute that means if you are changing admin it will call that particular URL hello admin function which is this or if your user is not giving admin it will call some other function I think I have a demo for it let me check and show you that let me stop this guy you see this is a program so I'll take the user name here and

18:34 whenever user gives some name and let's say the name is admin then I will send them to different page where it will call hello adminster if at all they didn't give me admin it will pass the call to the guest function guest URL slash guess slash guest slash whatever the name you pass here that's what the meaning of it so let's say if I run this guy and if I just say what is the URL route

18:58 slash user slash slash user slash Krishna if I say it will say hey hello Krishna you logged in as a guest you see the URL changed guess last Krishna because the page goes to this URL route but let's say you want to login as admin and hello adminster should come then you have to pass the name as admin then instead of this one if I pass admin it will say hello admin sir so what you are doing is in the same program

19:29 dynamically not statically this is static dynamically you are saying if the user has given name I'll send to one URL route which is hello admin which is this one should if URL is given us anything other than name if other than name admin anything else coming then you will send them to hollow guest that's the whole idea that's what called Dynamic URL routing and HTTP methods also you can manipulate you can do with get and post

19:52 also that's what HTTP method says in case you want to do it you can even manipulate on that that is also quite possible this get posts you mainly get and post people use get is basically for request where you are okay to expose the URL because on the URL the data will be sent when you use CAD whereas in the case of post the data will be sent over the body of the HTML not through the URL then

20:17 this is mainly used for confidential requests like your username password and all and this is mainly used for requests like search queries and all which is okay even if it's open publicly generally when we take requests either you take get or post based on the requirement so that's completely based on the project again so in this case what we are doing is there is a HTML page we are opening and that HTML page whenever user automatically gives a name this is the

20:45 HTML page the presentation layer of it and that presentation layer gets invoked here based on what is the post or get here that's how the routing is this is little Advanced so I'm not going to confuse you much here but understand you can even check what is the request method coming that means you are checking what is my HTTP request is it a post or get user is asking if he's asking post there is a HTML form which I

21:10 showed you this HTML page will come to users and it will ask for their login name here and if at all username is given as if at all the history method is getting as get then it will take to different page that's the whole area for you and apart from that flask also provides something called templates if you remember in the first slide we talk about Ginger Ginger 2 that's a template engine or the template language so

21:38 ideally that is like here HTML to be honest the reason is if you write everything in HTML like that it's not going to scale let's say the same HTML page you want to use for different pages like let's say you want to say this function has to be called for 100 users and every time you have to say let's say 100 users names you have to say hello Krishna for each user you want to say hello

21:58 let's say 100 employees are joining your company for all of the employees you have to say hello Krishna hello Sai hello Ram hello Alan hello Vicky like that for each of the users you want to call it that time if you put this it's not going to scale the best idea that point is you can have a separate HTML page where you will substitute the variable values which is nothing but the username in this case and that variable

22:20 names comes from who is opening the web page based on that you can do it that's where your template engine really works where rather than doing it what we do is we actually put it in a template so this is the ginger template where you put this and this is the variable part I am saying this name you will have to put it in two flower bases that's the notation you have to learn the ginger spelling

22:42 name is wrong it is j i n j a it's not GA by the way and this name how it comes is it comes from your code like whoever is opening page hello user that follow user if let's say slash hello Krishna is coming that Krishna gets passed from here and this one this Hello dot HTML is this so this name which you are passing gets substituted in the place of this that way you will have a different HTML

23:07 page rendering this is just one part of the template engine there are even attributes you can write if conditions like this like this percentage if like that you can do a lot of if conditions you can even have looping also okay so this is on the looping part so only when you deeply go into that template engine you will learn more about it but high level understand about it that you can put Loops also on your

23:33 HTML and these two flower bases means the variable names which comes from this in static files when I say static files files which is not dynamic pure you know hard code if you're not hard coded pure standard files they'll not change something like a basic HTML phase CSS files those are all static files if you want flask you can even do that jss or css files you again you can put that also so here in this case it is a plain

23:59 HTML page okay but if at all you have CSS you can also put that in the template file like you see here they are putting some js file okay you can also do that if you want and the request object if you look at we already looked at that request equal to get or post the same thing here we are talking but how it can be used like for example in flask you can work on forms

24:22 forms are nothing but HTML forms or you can take the arguments over the URL or you can work on cookies you can work on the file I mean there are different different libraries in flask in flask itself you have multiple libraries available for achieving each one of it similarly the cookies support if you see cookie is nothing but a key value pair right so that particular thing which is stored in the client machine also if you

24:45 want to retrieve or do something you can easily do that so this is the set cookie method all that you can do it using this response.set cookie this response again comes from a library that you need to import it if you see redirect we already have seen so one kind of redirection If You observe closely this is nothing but redirection only whenever user gives admin you are sending them to hollow admin page and dollar admin Pages this

25:11 guy so this is the same redirect which they are talking here so this is that redirect you can send which location register go what is the status code and what is the response and there's a set of standard codes these are HTML one space Kelly 400 200 the same thing you can reuse also in flask and apart from that flask has some concept called extensions because flask directly do not support any back end if you work on web application development

25:39 framework basically there are three things which are mandatory one is your front end another is your controller another is back-end flask by default does not support any backend database if at all you want to do it you have to make use of these extensions the flask EXT what they believe is they say that it should we should leave the choice to user on what database to use we should not be imposing it that's what their thought process is so that's why they do

26:02 not provide anything specific so for a database if you want to do they have different different support like for example if you want to do database like SQL Academy you have the support similarly MySQL you want you will have something like another extension for MySQL similarly there are extensions for emailing there are extensions for jqueries and all that Ajax and all and there's an extension for WTF forms also so this all comes in like a plug-and-play kind of architecture

26:28 whereas one difference you see when you learn about Django is in the jungle this is also built in they use sqlite3 by default but if you want to change to any database it is just configuration changes but here that support is not default available you have set it you have to set it up that's all from my side thank you all thanks for your time we'll see you in some other session see you all bye

Summary

Krishna discusses Flask, a lightweight web application framework for Python, covering its installation, routing, templates, and extensions. He emphasizes the importance of understanding Python basics and the advantages of using Flask for web development, particularly for smaller applications.

- Flask is a web application development framework written in Python, designed for ease of use and rapid development.
- It supports routing, allowing developers to map URLs to functions, enabling dynamic web pages.
- Flask uses Jinja2 as its template engine, allowing for dynamic HTML rendering with variables and control structures.
- Installation of Flask can be done easily using pip, preferably within a virtual environment.
- Flask does not come with built-in database support; instead, it relies on extensions for database integration and other functionalities.
- The framework is open-source and has a large community for support and resources.
- Flask is particularly suitable for small to medium-sized applications, while Django is recommended for larger projects.
- Understanding HTTP methods (GET and POST) is crucial for handling web requests and responses in Flask applications.

Questions Answered

What is Flask and what are its prerequisites?

Flask is a web application development framework written in Python. It is essential to have a basic understanding of Python, which is an object-oriented, high-level programming language. Python supports various programming paradigms, including procedural and object-oriented styles.

What are the advantages of using Flask for web development?

Flask provides a simple setup for web application development, allowing developers to focus on building applications without worrying about extensive configurations. It uses the Jinja template engine to render HTML, facilitating the separation of UI, controller, and backend functionalities.

How can you configure Flask applications, including debugging and routing?

Flask applications can be configured to run on different hosts and ports. The debug mode is useful during development as it displays errors clearly, but it should be turned off in production to prevent exposing code to users. Routing in Flask allows for the handling of different URL patterns and data types.

How does Flask handle different data types in URL routing?

Flask can retrieve different data types from URLs, such as integers, floats, and strings. This flexibility allows developers to create dynamic routes that can process various types of input.

Why are templates important in Flask, and how do they work?

Templates in Flask, specifically using the Jinja template engine, allow for dynamic content rendering. Instead of hardcoding HTML for each user, templates enable the substitution of variable values, making it scalable and efficient for applications with multiple users.

© transcribe · For agents Built with care and craft by Gokul Rajaram