Placeholder Image

Subtitles section Play video

  • What's going on, everybody.

  • And welcome to an update to the Web development in Python with Django tutorial Siri's.

  • It's been about three years since I covered Django, so I think it's about time to do a little bit of an update.

  • Plus, everybody had been asking for something a little more in depth last time.

  • So hopefully gonna kill two birds, one stone.

  • So here we have the Django home page.

  • You actually don't have to go here, but this is their website.

  • They've got documentation and all that.

  • Definitely check that out.

  • They also have a pretty decent tutorial that's worthy of following us.

  • Well, especially if you guys are getting confused on how things work in Django and stuff like that.

  • So Django is kind of Ah, hi initial investment for you, or at least for most people, because the understanding had this whole model view controller thing works, and all the connections that need to be made can be kind of a challenge initially.

  • But I promise, if you stick through, it's definitely worth it in the end, because as your project grows and you need to make changes or at new things, using something high quality like Django is going to make it unbelievably easy for you down the line.

  • It's just a little harder to get started.

  • But hopefully I can make it easier for you guys.

  • So it's going to get into it.

  • Enough chitchat.

  • I think the best way to learn Jango and really anything is to just do it.

  • I'm gonna assume you guys know the basics of Python.

  • If you don't follow any basics tutorial, you can go to Python program and that come to the fundamentals Boom.

  • There's a basic Siri's there or anyone else is just I just know the basics.

  • Okay, so, uh, let's go get started.

  • So the first thing Oh, a couple of the things I'm gonna mention is I'm gonna be using the sublime text editor.

  • You don't have to use sublime text.

  • You could use any editor you want.

  • You could use note pad plus plus or no pad for that matter or pie charm or whatever use whatever you want.

  • The other thing is, I'm gonna be doing some of the development on a Windows machine and then later will be on Lenox Server eventually.

  • If you're going to deploy a website chances are you're gonna be on Lenox somewhere.

  • So anyway, your operating system doesn't matter.

  • I've also done a lot of development on Mac.

  • I've done it on Windows and I've done on Lenox.

  • It just doesn't matter.

  • So, um, we're gonna be using Python 3.7 here.

  • Eso also, I'm assuming you've got Python installed already.

  • And with that, let's go ahead and get started.

  • So the first thing I'm gonna do is hopefully not drool out of my mouth and, uh, opened up a command window and we're going to a pip install.

  • Jingo, if you're on Lennox or Mac, you might say instead, like python three m pip installed Django or something like that.

  • Um, if you're on windows, it's Pip.

  • If you have multiple versions of python, then it would be like pie Dash 3.7 m.

  • Pip install.

  • Okay, I'm assuming.

  • Like I said, though, you guys already know that.

  • So take note.

  • We're using Django 2.1 point five here.

  • Uh, you don't have to use the exact version I use.

  • Just know that as things progress, things might be a little different from what I've seen.

  • A lot of things are still backwards compatible, and it's like totally fine.

  • Things are getting deprecate ID, but sometimes things are So, um, if something's not working out for you, for whatever reason, you could try to install the exact same virgin as I'm using to see if it's just a difference in version.

  • So, for example, if you wanted to, you could also say Pip install Django double equals 2.1 point five, and that will install exactly version 2.1 point five.

  • Now we'll just say before you deploy your your creation.

  • Um, make sure you're using the latest version of Django.

  • Uh, there's lots of things that change over time.

  • One of those things is like security fixes and stuff.

  • So if you're using an outdated Django, you might be making a mistake.

  • So So the only reason you should install a specific version that I'm using here is just so you could follow along and just learn about Django and then later learn what?

  • What's the difference between Let's say, Jen go to in Django 2.5 or something like that?

  • But probably unless this first number changes like Django three, something, uh, probably will get away with following along.

  • Anyway, let's see if we're done with the We are done with the install.

  • When you install Django, you get a little command line thing.

  • Hold Django admin.

  • We got all these things with Django admin, but the main thing that we're gonna do is start a project.

  • And, um, trying to think here, that's probably one of the main things that you're actually going to use jango admin for.

  • Um, apparently, you can do quite a few other things with Django admin, but instead you'll be using a different script.

  • So anyways, um, we're going to say is Django admin start project, and we're gonna call this project.

  • My sight the way Jingo works is it assumes all websites are actually just a collection of APS.

  • It could just be one app for sure, but it's probably a collection of app.

  • So consider a website that has, like, a forum, a store, and like a blogger or something like that.

  • Okay, Either of those things are separate taps here have a form app.

  • Gotta store wrapping a blah gap.

  • Okay, that's how Django sees things.

  • So when we start a project, our project is called my sight and within my sight, we're gonna have a bunch of APS that do things.

  • The thing that we're gonna dio is, uh, we're gonna create a website that's like python programming dot net.

  • I've been considering switching Python programming that net over to Django.

  • Currently, it's written in a flask.

  • And for the reasons I mentioned before, as the whips, a za project grows in flask, trying to add new elements and change things over time becomes very tedious.

  • With Django, it's just not so, um I mean, there's always makes me think of a comment comic.

  • I've done it again.

  • Wow, If I could type, haven't tied.

  • I bet if I go to images, hopefully we don't see it yet.

  • Hopefully, nothing on here is what we shouldn't have saved searches on.

  • Anyways, this is the comic I always think of.

  • You know, you start off a project, you think you're doing great.

  • And then at the end of the day, it it looks something more like this.

  • And initially, as we're setting up Django, it's gonna feel like we're doing this.

  • But the thing is, that is complex as it will ever get, as opposed to Ah, project like python programming.

  • That net where there's so many little connections going all over the place, it really is a challenge.

  • I do think it's worth it to use Jango long term, Just hard toe initially get into it.

  • But anyways, start project my sight.

  • Boom.

  • Let's create my sight.

  • And what's gonna happen is we should have a new directory.

  • We sure do.

  • Called my sight.

  • This is your your project right inside of your project.

  • You have another directory called my site.

  • And then we have managed a pie, which is actually what we're going to use to do much of the things coming up.

  • So, um, inside of this my sight directory.

  • This is kind of like an app already, but I'm gonna refer to this.

  • There's probably a special term in Django.

  • I just don't know it.

  • I'm gonna call this You're, like, primary app inside of this app.

  • Really?

  • All this app is going to do is point to your other APS.

  • You're not gonna use this.

  • You're gonna actually developing here other than to point to other APS and adjust the settings.

  • Other than that, you're not gonna really do anything.

  • I'm sure zoom in a little bit.

  • So coming back out to this directory, we want to play with managed up pies.

  • So I'm gonna open up a command window here if you hold shift and right click.

  • By the way, that's how I get that.

  • You also, if you're on Windows, could just do CMD That should also open up a command window right where you are.

  • So the first thing that we're gonna do is start an app.

  • So I'm gonna say, uh, it's a pie.

  • Dash 3.7 actually could just say python because I only have one version, but anyways, pie 3.7, manage dot pie start app, and then we're gonna call this app main, so this will be like the main core of the website.

  • So for me, this is where, like, we're gonna put like tutorials like the main aspect is tutorials.

  • And if anything, I could probably call this tutorials as well, but I'm probably gonna want to put other things inside of Maine besides just tutorials.

  • So I'm gonna call it main for now.

  • So we've created an app Cold man.

  • If we come back, we should see we've got another directory here called Main.

  • If we open that up, it looks a lot like or my sight directory or our primary app.

  • But we've got actually some extra things here.

  • And as we can see, we've got models views.

  • Where's the controller?

  • We actually don't have any controller here, but we'll get there.

  • I promise.

  • So, um, what we want to do now is, um Let's go ahead.

  • I'm gonna get this just to stay running now.

  • So what I'm gonna say I'm gonna move.

  • Have to command prompts here.

  • 1st 1 I'm gonna do is we're gonna use managed a pie, and we're actually just going to say run server.

  • So run server.

  • And what this does is runs your development server.

  • You, in theory, could run a whole website off of this.

  • It just isn't recommended price for all sorts of reasons, including security reasons.

  • Anyway, you can see we've got some, uh, migration issues that weaken worry about later, but mainly we can see that the website is now running at basically local host on Port 8000.

  • So, uh, let's head there.

  • We'll see what we got pieced.

  • Okay, so you get this little beautiful imagery and it just kind of notifies you.

  • Hey, things are working sort of up to this point, but rather than having this kind of display, I think it's a little cooler toe.

  • Have you no control?

  • Like, how do I change all of these things?

  • So let's get into it.

  • So first of all, with the model view controller, it kind of works almost like in reverse of that.

  • You've got your controller, which basically takes the girl that whoever typed in or clicked on a link that went to that you are Oh, the controller takes that you are Oh, and maps that two of you And then that view returns the template.

  • Now, most of the time that views also gonna interface with your models, but it doesn't actually have to.

  • Really?

  • You just need a controller interview to return something.

  • So let's go ahead and do that just so we can start to pick up how all of this this stuff works.

  • So, uh, the first thing that we're gonna do is, um let's just create inside of Maine here.

  • We don't have a u.

  • R l stop eye.

  • So we need to create one.

  • The other thing we could do is go into my sight.

  • Take this year old stop.

  • I I'm just gonna say copy that, and then I'm gonna come in two main paste.

  • And now we have a you earl's dot pie.

  • Um, I'd love to know.

  • Like, why it doesn't by default come like when you start a new app.

  • Why it doesn't have your world stop I by default.

  • If anybody actually knows that, be cool.

  • So this is like the first time I'm using this, uh, this machine.

  • So I've gotta add sublime text really quick to the thing that I wanna open.

  • Great.

  • The other thing I probably need to do before I forget.

  • Intend using space is done.

  • Okay, so this is what, um are you world's top?

  • I just make sure you're in Maine.

  • Not my sight.

  • Actually, I think it would make most sense to start in, um, in the my sight you rose up high because when someone first comes here, what it's gonna do is its first gonna look to your primary app, and it's gonna look at that.

  • You Earl, stop I and that's going to see.

  • Do we have a euro pattern that matches and needs to have your old pattern that matches.

  • But generally your primary app is just going to have a pattern that matches and points to some other app.

  • So the first thing we're gonna actually do let me go file open folder, and then let's open my sight.

  • And then I'm just gonna close this.

  • And I think this is how we're gonna interact from here.

  • Out.

  • Um, so I'm gonna go into first.

  • Let's go to my site.

  • You earl's dot pie.

  • So primary app.

  • I switched around.

  • Don't get confused.

  • Your fault.

  • Um, So what we want to do here is we just need to take this because it's our primary app and pointed to our new app called Maine.

  • So we're gonna add another path year.

  • I'm gonna copy this, come down here and I'm gonna paste.

  • And then what I'm gonna say is, uh, we're gonna Well, first, let's also import, include, and then what we're gonna say for this path is an empty path.

  • So, home page, No other girls are being submitted here.

  • We want to include main dot your l's.

  • So whenever someone comes to just just the home page and there's nothing else that this path is gonna match.

  • So then it's going to say, OK, let's go to maine dot your l's now.

  • So then we're gonna go to Maine, You or else make sure you're in Maine, you or else.

  • And now we want to do is actually we don't need admin here.

  • Um, so I'm gonna delete that for now, and then we're going to say, and we don't need this admin either.

  • We'll keep path, and then the other thing we're gonna do is from just relative important views.

  • And then we're gonna pass in APP name, and we're gonna say apt name equals main.

  • This is useful.

  • Later on, when you're trying to create custom, you are l's that will point to a specific view, but you don't actually have to hard code the earl.

  • It's all totally dynamic.

  • So right now we're not using that, but I just want to forget about it later.

  • And you might as well just always throw this in because eventually you'll wanna have that functionality and you'll try to use it because you saw it in an example somewhere or something, and it's not gonna work and you're gonna like Wait.

  • What?

  • So anyway, we'll throw that in there for now.

  • So then we're gonna say path.

  • And again, the path would be home page because, like, right now, all paths will lead to this year old stop.

  • I So But for now, we're going to say, OK, the empty path is gonna point towards a views dot home page, and they're gonna give this also a name called Home Page.

  • I'm gonna put a common here before I forget, because later on, we'll add more paths and throw syntax error if we messed that up.

  • Okay, so going back over, someone comes here, they visit the home page.

  • First we go to our primary app comes here says, Oh, hey, look, here's a path that matches what they just put in.

  • There's nothing else here.

  • Cool.

  • What do we do?

  • Include main dot your l's find boom points to main dot your l's become here path.

  • Okay, this points to a view.

  • It's the home page function in that view.

  • Okay, great.

  • Unfortunately, we don't have, um, the view done.

  • So if we come into our main area here and impacted said I was gonna keep using this.

  • So I think we'll keep using this.

  • We come in two main.

  • We can click on views dot pie.

  • And here we have what we need to bring in views.

  • Now, render is used to render templates.

  • I just want to pass a simple string right now.

  • Don't want to get into template.

  • So the next thing to say is from jango dot http report http response Now define home page, and then we're gonna pass a request.

  • So basically all your actual views, if you have, like, a helper function or something and obviously doesn't need requests, but for any actual view, you pass request always.

  • Um and then obviously, this is the name that we passed right here, right?

  • We said views dot home page.

  • So that's why it's called home page.

  • Now, all we're gonna say is return http response.

  • And then we can pass actual html here.

  • Even so, we could say, um wow, this is an tutorial, and you can feel free to put whatever you want in there.

  • I'm gonna say awesome.

  • Okay, say that.

  • Great.

  • So now let's make sure server still running.

  • Do we hit any errors?

  • I don't see anything just yet, So let's come over here.

  • Let us refresh the page.

  • Boom.

  • Don't let me zoom in a little bit, just so everybody can see how.

  • What kind of a tutorial?

  • Awesome to door.

  • Okay, um, I think this is a good stopping point before we get into the next tutorial, which is where we're gonna talk about models and stuff like that and quickly start to ramp up.

  • But the big thing is, you have to understand even just this basic stuff, because that was actually a lot of work to go through just to return some text on the page.

  • So what I I strongly suggest you do is after this video before you go to the next one is try to do everything we just did on your own without needing to look anything up.

  • I mean, obviously, you might forget something like the import names or something like that.

  • But even then, it's just Denko HDP http response.

  • Um and then the only other import you need is thea include here, So you should be able to do this completely on your own now.

  • And so what I would suggest you do is create a new, you know, start a new project and try to do all of the things that we've done up to this point without needing to reference anything.

  • Um, obviously as you as time goes on, that won't be necessary that you could make an entire website without being well, look anything up.

  • But it's important that you understand how these initial connections are made before you continue on, because it only gets a little more complex from here.

  • So anyways, that's it for now.

  • A quick shout out to my most recent channel members.

  • A Danish Kumar, Luciano Sena opponents and Bethany and Uday Man Shonda, Thank you guys very much for your support.

  • You guys are awesome.

  • Also, side note this Siri's is sponsored in part by Lin owed, which is who have actually used to host Python programming that net for like years.

  • Also, there might basically they're my main host for, like, larger websites, and we'll be using winnowed as, uh, as our deployment virtual private servers down the line.

  • But for quite a while, we'll just developed locally because I think that's really the way to go anyways.

  • But if you want to check out.

  • Leonard, you need a hosting solution.

  • I'll put a link in the description from them, but later on we'll actually go through how you can actually launch a jangle application online owed.

  • And actually, you know why Something like Leonard is better than some of the other options that you have out there.

  • Trust me, I've used all of them anyways.

  • That's it for now.

  • Questions, comments, concerns, whatever.

  • Feel free to leave below.

  • Also, we have a discord service.

  • Just discord dot g slash Centex in your browser gets you there.

  • Come hang out.

  • Come chat with us.

  • Ask questions.

  • Whatever.

  • Tell me how how I can improve my tutorials, all that kind of stuff.

  • Anyways, I will see you guys in the next video.

What's going on, everybody.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it