Python Flask WebDev [02] URL Routing

John Hammond · Intermediate ·🔧 Backend Engineering ·7y ago

Key Takeaways

Demonstrates URL routing using Python Flask

Full Transcript

what's up guys this is John Hammond so in the last video we were taking a look at flasks for Python and we essentially made pretty much just identical to the example application from their their hello world program and the QuickStart guides and the online documentation so now I want to try and move on to some other stuff but first I want to take note of debug mode because it's pretty awesome for us as developers while we're learning and experimenting with flask debug mode will allow us to essentially work in a development environment that allows us to do some pretty cool things for one thing it activates the debugger so if things go wrong in your program you can take a look at the variables and execute code while still being inside the application and the most important thing I think it does for us is it will reload our application if it sees a change in the source code that's pretty awesome while we were trying to develop and test things on the fly so it explains how to do this with some environment variables but another notion is just turning on debug or setting flashing debug equal to one if you want to use debug mode without being defined in a development environment you can do that with those environment variables on the command line but another option is in your source code just say debug equals one or true as a keyword argument to your application run script so before I do that I wanted to showcase how this looks when you don't specify that you'll notice that debug mode is off here and we're in that running in that same application but if I were to change debug equal to true suddenly we will have okay debug mode is on and we will be able to restart as we see changes in the source code so now that we have debug mode on it will reload our program automatically for us that's pretty cool there is a strong note though because the interactive debugger will essentially stop your program and show errors whenever things go wrong it gives you means to test your code and execute actual arbitrary code that is not good if it's kind of found in the wrong hands right so it can be a huge security risk if you leave it on for something that you actually put on the internet because you don't want to just give your the users like little remote code execution on your on your web server and Python so that can that's bad do not use debug mode when you're putting something for real on the Internet okay cool the next thing I wanted to get into was moving into URL routing because we talked about that application route earlier and then in the previous video but now we can expand that let's say we wanted to be have a new route called say hello or say hello and it would be like hello YouTube and remember we'll have to change the name of this function because we don't want it to match the same as the other one that will have an error here now the moment I save this you'll see that detection or that change being found in the debugger so if I were to access this page right here one two seven zero zero one or localhost running on that development port 5,000 we have hello world as usual but we also have say hello which we can read and it says hello YouTube just like that so say we didn't want to greet just YouTube we wanted to greet anyone in particular and that's pretty neat because we had the option to use variables inside of the URL there's some notes here in the documentation that explain how you can use it but essentially it's just denoting with greater than and less than symbols for the variable that you want inserted into that URL it can be anything but you'll have to pass that in as an argument to your function here so if I wanted to say say hello to someone we can have say hello and then user name can be named and they'll taken this part given name so we will say hello with a formatted string based off name and I will change some of these documents strings here even though they're annoying sorry okay cool so now you'll see those changes being loaded and you'll see when we're actually loading pages that's denoted and then captured in the log of our server so that's pretty neat and cool to watch if you are doing anything for even maybe like a pen test if you're trying to see if you have an active connection it's good to log all those connections here so let's go ahead and check out that page one more time now not only can I say hello on its own but I can say hello to like John and it says hello John and you'll see my name is supplied as a variable and we can have anything in there like Doug hey Doug okay that documentation explains a little bit more where you can specify specific formats and specific types like if you want a specifically a string that's the default in this case we didn't specify its own name was cast to a string integer float etc etc that's an option that we have here and remember these forward slashes you can like have as many of these as you want to anyone with a lot of slashes like you can build out essentially a path through it looks like directories or how you'd normally see it if you were trying to write something in PHP but you're doing it in Python and you can define whatever URL you particularly want because flats believe flats believes that URL should be beautiful they should be simple and clean without any file extension like dot PHP or dot aspx all that crap so you can have fine fine tune control and a lot of granular specification in this and that's a pretty neat thing so keep in mind those variables you want to pass to to a URL if you're trying to keep track of a unique identifier or something that has to be passed as a variable to your function as well so neat thank you guys for sticking with me I do need to give a little shout-out to my supporters so super huge props to these guys because they sent me a little bit of love and I cannot thank you enough for that every little bit helps $1 a month on patreon will give you a shout out just like this at the very end of the video 5 a month that gives you some early access to videos that are record on YouTube before they actually get released so if you did like this video please do like maybe comment if you're willing to subscribe and check me out on patreon thanks so much guys see you soon

Original Description

If you would like to support me, please like, comment & subscribe, and check me out on Patreon: https://patreon.com/johnhammond010 E-mail: johnhammond010@gmail.com PayPal: http://paypal.me/johnhammond010 GitHub: https://github.com/JohnHammond Site: http://www.johnhammond.org Twitter: https://twitter.com/_johnhammond
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from John Hammond · John Hammond · 0 of 60

← Previous Next →
1 Code Commentaries? PHP to JavaScript in Bash and PHP!
Code Commentaries? PHP to JavaScript in Bash and PHP!
John Hammond
2 Tutorials? MySQL connection with PHP and Bash!
Tutorials? MySQL connection with PHP and Bash!
John Hammond
3 Variable Naming in Python! Happy Birthday, Linux! Nokia N900!
Variable Naming in Python! Happy Birthday, Linux! Nokia N900!
John Hammond
4 JavaScript Splits The URL!
JavaScript Splits The URL!
John Hammond
5 HTML Tables in Python!
HTML Tables in Python!
John Hammond
6 HTML, Net Shares, GML!
HTML, Net Shares, GML!
John Hammond
7 Python 08 Programming Style and Comments
Python 08 Programming Style and Comments
John Hammond
8 Python 26 Object Oriented Programming
Python 26 Object Oriented Programming
John Hammond
9 75 Python Tutorials, Out Now!
75 Python Tutorials, Out Now!
John Hammond
10 Batch 14 Mathematical Expressions
Batch 14 Mathematical Expressions
John Hammond
11 Batch 85 Array Append
Batch 85 Array Append
John Hammond
12 Batch 86 Array Count
Batch 86 Array Count
John Hammond
13 Batch 87 Array Index
Batch 87 Array Index
John Hammond
14 Batch 88 Array Insert
Batch 88 Array Insert
John Hammond
15 Batch 89 Array Remove
Batch 89 Array Remove
John Hammond
16 Batch 90 Array Reverse
Batch 90 Array Reverse
John Hammond
17 Python [colorama] 00 Installing on Linux
Python [colorama] 00 Installing on Linux
John Hammond
18 Python [colorama] 09 Cursor Position
Python [colorama] 09 Cursor Position
John Hammond
19 Python [hashlib] 02 Algorithms
Python [hashlib] 02 Algorithms
John Hammond
20 Python 00 Installing IDLE on Linux
Python 00 Installing IDLE on Linux
John Hammond
21 Python [pygame] 11 Rectangular Collision Detection
Python [pygame] 11 Rectangular Collision Detection
John Hammond
22 Python [pygame] 12 Platforming Rectangular Collision Resolution
Python [pygame] 12 Platforming Rectangular Collision Resolution
John Hammond
23 Python [XML-RPC] 01 Research
Python [XML-RPC] 01 Research
John Hammond
24 Python [pyenchant] 03 Personal Word Lists
Python [pyenchant] 03 Personal Word Lists
John Hammond
25 FancyURLopener Authentication and User-Agent [urllib] 03
FancyURLopener Authentication and User-Agent [urllib] 03
John Hammond
26 Python 04: PEP8 Coding
Python 04: PEP8 Coding
John Hammond
27 Python Challenge! 17 COOKIES
Python Challenge! 17 COOKIES
John Hammond
28 Google CTF 2016: Ernst Echidna
Google CTF 2016: Ernst Echidna
John Hammond
29 Google CTF 2016: Spotted Quoll
Google CTF 2016: Spotted Quoll
John Hammond
30 Google CTF 2016: Can you Repo It?
Google CTF 2016: Can you Repo It?
John Hammond
31 Google CTF 2016: No Big Deal
Google CTF 2016: No Big Deal
John Hammond
32 Google CTF 2016: In Recorded Conversation
Google CTF 2016: In Recorded Conversation
John Hammond
33 Homemade CTF Challenge: 01 "Orchestra"
Homemade CTF Challenge: 01 "Orchestra"
John Hammond
34 Homemade CTF Challenge: 02 "Bae's Base"
Homemade CTF Challenge: 02 "Bae's Base"
John Hammond
35 Homemade CTF Challenge: 03 "Web Hunt"
Homemade CTF Challenge: 03 "Web Hunt"
John Hammond
36 Homemade CTF Challenge: 04 "UPX"
Homemade CTF Challenge: 04 "UPX"
John Hammond
37 Homemade CTF Challenge: 05 "The Assumption Song"
Homemade CTF Challenge: 05 "The Assumption Song"
John Hammond
38 Homemade CTF Challenge: 06 "A Brisk Stroll"
Homemade CTF Challenge: 06 "A Brisk Stroll"
John Hammond
39 Homemade CTF Challenge: 06 "I lost my password!"
Homemade CTF Challenge: 06 "I lost my password!"
John Hammond
40 web25 :: Mr. Robot : EKOPARTY CTF 2016
web25 :: Mr. Robot : EKOPARTY CTF 2016
John Hammond
41 web50 : RFC 7230 :: EKOPARTY CTF 2016
web50 : RFC 7230 :: EKOPARTY CTF 2016
John Hammond
42 misc50 : Hidden inside EKO :: EKOPARTY CTF 2016
misc50 : Hidden inside EKO :: EKOPARTY CTF 2016
John Hammond
43 Hack The Vote 2016 CTF: Sander's Fan Club [web100]
Hack The Vote 2016 CTF: Sander's Fan Club [web100]
John Hammond
44 Hack The Vote 2016 CTF Warpspeed [forensics150]
Hack The Vote 2016 CTF Warpspeed [forensics150]
John Hammond
45 Juniors CTF 2016 :: Black Suprematic Square
Juniors CTF 2016 :: Black Suprematic Square
John Hammond
46 Juniors CTF 2016 :: Six Strange Tales
Juniors CTF 2016 :: Six Strange Tales
John Hammond
47 Juniors CTF 2016 :: Lost Code
Juniors CTF 2016 :: Lost Code
John Hammond
48 Juniors CTF 2016 :: Here Goes!
Juniors CTF 2016 :: Here Goes!
John Hammond
49 Juniors CTF 2016 :: Southern Cross
Juniors CTF 2016 :: Southern Cross
John Hammond
50 Juniors CTF 2016 :: Clone Attack
Juniors CTF 2016 :: Clone Attack
John Hammond
51 Juniors CTF 2016 :: Dirty Repo
Juniors CTF 2016 :: Dirty Repo
John Hammond
52 Juniors CTF 2016 :: Hackers Blog
Juniors CTF 2016 :: Hackers Blog
John Hammond
53 Juniors CTF 2016 :: Voting!!!
Juniors CTF 2016 :: Voting!!!
John Hammond
54 Juniors CTF 2016 :: The Good, The Bad and The Junkman
Juniors CTF 2016 :: The Good, The Bad and The Junkman
John Hammond
55 Juniors CTF 2016 :: Stop Thief!
Juniors CTF 2016 :: Stop Thief!
John Hammond
56 Juniors CTF 2016 :: ROFL
Juniors CTF 2016 :: ROFL
John Hammond
57 Juniors CTF 2016 :: Restriced Area
Juniors CTF 2016 :: Restriced Area
John Hammond
58 Juniors CTF 2016 :: Oh SSH!
Juniors CTF 2016 :: Oh SSH!
John Hammond
59 HackCon CTF 2017 TRIVIA and BONUS Challenges
HackCon CTF 2017 TRIVIA and BONUS Challenges
John Hammond
60 HackCon CTF 2017 "Bacche" Challenges
HackCon CTF 2017 "Bacche" Challenges
John Hammond

Related AI Lessons

Up next
This Cop Was Held Accountable For His Brutality! #police #lawyer
Hampton Law
Watch →